-
-
Save ryupold/fe38e5acbe1586681e27 to your computer and use it in GitHub Desktop.
private string GetImageFromURI(Uri contentURI) | |
{ | |
return MediaStore.Images.Media.GetBitmap(ContentResolver, contentURI); | |
} |
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; | |
} |
Works perfectly!
send {content://com.android.providers.media.documents/document/image%3A45}
get /storage/emulated/0/Download/20170720_105923.jpg
Hi, I wanted to use it, however I get an error : An object reference is required for ContentResolver.Query
. Any help would be very much appreciated!
EDIT : My mistake! Since I am using this code inside a fragment, I just needed to use the activity context like this Activity.ContentResolver.Query
and it works amazingly!!
How can take video file real path can any help me
Ha ha! Your code is related to images files but what to do with any others files? Forexample, exe, db3, doc, pdf...
Ha ha! Your code is related to images files but what to do with any others files? Forexample, exe, db3, doc, pdf...
Me also looking for the same solution
Any solution for others files?
I got cursor null reference, do you have any suggestion?