I have downloaded an image from Google Drive storage. I want to set this image to imageview in my app using Gallery Intent.
Uri of image received in onActivityResult: content://com.google.android.apps.docs.storage/document/acc%3D2%3Bdoc%3Dencoded%3DWe%2BdXDcNgTeulVk1Ntu3YfRYkm9wk7uTdTG6LFVyck1BxY4g7xAxyPAgtMtz4A%3D%3S
I am using this code get the real-path from the url:
if ("com.google.android.apps.docs.storage".equals(uri
.getAuthority())) {
//content://com.google.android.apps.docs.storage/document/acc%3D2%3Bdoc%3Dencoded%3DWe%2BdXDcNbYeulVk1Ntu3YfRYkm9wk7uTdTG6LE6yck1BxY4g7xAxyPAgtMtz4A%3D%3D
final String docId = DocumentsContract.getDocumentId(uri);
final String id = docId.split(";")[1];
final String[] selectionArgs = new String[]{id};
//String[] column = {MediaStore.Images.Media.DATA};
// where id is equal to
String selection = MediaStore.Images.Media._ID + "=?";
Uri contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
//..
Cursor cursor = null;
String filePath = null;
try {
String[] column = {MediaStore.Images.Media.DATA};
cursor = context.getContentResolver().query(contentUri,
column, selection, selectionArgs, null);
if (cursor != null && cursor.moveToFirst()) {
int columnIndex = cursor.getColumnIndex(column[0]);
filePath = cursor.getString(columnIndex);
}
} finally {
if (cursor != null)
cursor.close();
return filePath;
}
}
.....
But I am getting NULL cursor. Thus, filepath is always empty/null.
Anyone, could please suggest what I am doing wrong?