Last active
January 18, 2024 21:13
-
-
Save alexzaitsev/75c9b36dfcffd545c676 to your computer and use it in GitHub Desktop.
Get image/video file path from New Google Photos app Uri
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (isNewGooglePhotosUri(uri)) { | |
String pathUri = uri.getPath(); | |
String newUri = pathUri.substring(pathUri.indexOf("content"), pathUri.lastIndexOf("/ACTUAL")); | |
return getDataColumn(context, Uri.parse(newUri), null, null); | |
} | |
public static boolean isNewGooglePhotosUri(Uri uri) { | |
return "com.google.android.apps.photos.contentprovider".equals(uri.getAuthority()); | |
} | |
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { | |
Cursor cursor = null; | |
final String column = "_data"; | |
final String[] projection = { | |
column | |
}; | |
try { | |
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); | |
if (cursor != null && cursor.moveToFirst()) { | |
final int index = cursor.getColumnIndexOrThrow(column); | |
return cursor.getString(index); | |
} | |
} finally { | |
if (cursor != null) { | |
cursor.close(); | |
} | |
} | |
return null; | |
} |
@arindamxd your suggestion helped, was trying to solve it for a day, thanks :)
@Parag2385 welcome :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try this one https://stackoverflow.com/a/50253933/8515192