Last active
June 3, 2020 09:31
-
-
Save ryupold/fe38e5acbe1586681e27 to your computer and use it in GitHub Desktop.
Get file path from Content-URI in Android (Xamarin)
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
private string GetImageFromURI(Uri contentURI) | |
{ | |
return MediaStore.Images.Media.GetBitmap(ContentResolver, contentURI); | |
} |
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
private string GetRealPathFromURI(Uri contentURI) | |
{ | |
ICursor cursor = ContentResolver.Query(contentURI, null, null, null, null); | |
cursor.MoveToFirst(); | |
string documentId = cursor.GetString(0); | |
documentId = documentId.Split(':')[1]; | |
cursor.Close(); | |
cursor = ContentResolver.Query( | |
Android.Provider.MediaStore.Images.Media.ExternalContentUri, | |
null, MediaStore.Images.Media.InterfaceConsts.Id + " = ? ", new [] { documentId }, null); | |
cursor.MoveToFirst(); | |
string path = cursor.GetString(cursor.GetColumnIndex(MediaStore.Images.Media.InterfaceConsts.Data)); | |
cursor.Close(); | |
return path; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Me also looking for the same solution