I´m trying to access a file to send it via POST
with Retrofit, but everytime and with any file i´m getting java.io.FileNotFoundException: /document/image:182 (No such file or directory)
I´m asking permission in runtime, app is min API 23 (Marshmallow), I´m getting the uri fine (i guess), the uri.Path is correct (/document/image:182)
but with diferent name ("file.jpg")
I don´t know if this is ok or not.
the code
case R.id.adjuntar_archivo:
if (this.requireContext().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_DENIED) {
String[] permissions = {Manifest.permission.READ_EXTERNAL_STORAGE};
requestPermissions(permissions, OPEN_PERMISSION);
} else {
openFile();
}
break;
private void openFile() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, OPEN_REQUEST_CODE);
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == OPEN_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
if (data != null) {
if (data.getData() != null) {
uri = data.getData();
//hasAttachment is for POST request with/without attached file
hasAttachment = true;
}
}
}
}