I'm using the following code to convert file uri(which is selected from the sdcard/external memory) into path and upload this path to server. while uploading files from internal memory its working perfectly. When I'm trying to select a file from external memory/sdcard to the server I'm getting java.io.fileNotFoundException:/mnt/media_rw/:/open failed: EACCESS(Permission denied).And I have included all the permissions in Manifest file.
private String getRealPathFromURI(Uri contentURI) {
String result;
Cursor cursor = getContentResolver().query(contentURI, null, null, null, null);
if (cursor == null) { // Source is Dropbox or other similar local file path
result = contentURI.getPath();
} else {
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA);
result = cursor.getString(idx);
cursor.close();
}
return result;
}