// Source - https://stackoverflow.com/a/46431435
// Posted by Adeeb karim
// Retrieved 2025-11-22, License - CC BY-SA 3.0
private void setImagePath(Intent data) throws Exception {
String wholeID="";
Uri selectedImage = data.getData();
if(Build.VERSION.SDK_INT\<=Build.VERSION_CODES.JELLY_BEAN_MR2){
wholeID=getUriPreKitkat(selectedImage);
}else {
wholeID = DocumentsContract.getDocumentId(selectedImage);
}
// Split at colon, use second item in the array
Log.i("debug","uri google drive "+wholeID);
String id = wholeID.split(":")\[1\];
String\[\] column = {MediaStore.Images.Media.DATA};
// where id is equal to
String sel = MediaStore.Images.Media.\_ID + "=?";
Cursor cursor = getActivity().getContentResolver().
query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
column, sel, new String\[\]{id}, null);
int columnIndex = cursor.getColumnIndex(column\[0\]);
if (cursor.moveToFirst()) {
filePath = cursor.getString(columnIndex);
https://stackoverflow.com/a/46431435// Source - https://stackoverflow.com/a/63407339
// Posted by B.shruti
// Retrieved 2025-11-22, License - CC BY-SA 4.0
public static File getFile(final Context context, final Uri uri) {
Log.e(TAG,"inside getFile==");
ContentResolver contentResolver = context.getContentResolver();
try {
String mimeType = contentResolver.getType(uri);
Cursor returnCursor =
contentResolver.query(uri, null, null, null, null);
int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE);
returnCursor.moveToFirst();
String fileName = returnCursor.getString(nameIndex);
String fileSize = Long.toString(returnCursor.getLong(sizeIndex));
InputStream inputStream = contentResolver.openInputStream(uri);
File tempFile = File.createTempFile(fileName, "");
tempFile.deleteOnExit();
FileOutputStream out = new FileOutputStream(tempFile);
IOUtils.copyStream(inputStream,out);
return tempFile;
}catch (Exception e){
e.printStackTrace();
r
MediaStore.Images.Mediahttps://stackoverflow.com/a/63407339eturn null;
}
} }
cursor.close();
}