My app needs an option to upload image file, which is perfectly working for some files only. I am unable to distinguish between the image files, and why it's not working for every images. I am debugging this app on my Android 10 phone.
The following code I have written to get the file path from URI.
try {
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
cursor.moveToFirst();
String document_id = cursor.getString(0);
document_id = document_id.substring(document_id.lastIndexOf(":") + 1);
cursor.close();
cursor = getContentResolver().query(
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
null, MediaStore.Images.Media._ID + " = ? ", new String[]{document_id}, null);
cursor.moveToFirst();
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
cursor.close();
return path;
}
catch (Exception e){
Log.e("GET PATH EXCEPTION", e.getMessage());
return null;
}
It throws Index 0 requested, with a size of 0 exception