-1

I am trying to get real path for Picked image in Android 10 but it's not working Iam using the folowing code its work fine in android 9

public static String getRealPathFromURI(Context context, Android.Net.Uri contentUri)
        {
            ICursor cursor = context.ContentResolver.Query(contentUri, null, null, null, null);
            cursor.MoveToFirst();
            String document_id = cursor.GetString(0);
            document_id = document_id.Substring(document_id.LastIndexOf(":") + 1);
            cursor.Close();

            cursor = context.ContentResolver.Query(
            Android.Provider.MediaStore.Images.Media.ExternalContentUri,
            null, MediaStore.Images.Media.InterfaceConsts.Id + " = ? ", new string[] { document_id }, null);
            cursor.MoveToFirst();
            String path = cursor.GetString(cursor.GetColumnIndex(MediaStore.Images.Media.InterfaceConsts.Data));

             cursor.Close();
            return path;
        }
AYKHO
  • 516
  • 1
  • 7
  • 20

1 Answers1

0

Option1

After SDK 29.0 ,DATA is deprecated . Apps may not have filesystem permissions to directly access this path. Instead of trying to open this path directly, apps should use ContentResolver#openFileDescriptor(Uri, String) to gain access.

Here is a similar thread which you can refer .

Option 2

You could install the plugin Xam.Plugin.Media from nuget .

Usage

await CrossMedia.Current.Initialize();

if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
     return;
}

var file = await CrossMedia.Current.PickPhotoAsync();

if (file == null)
     return;

var path = file.Path;

For more details about the plugin you could check https://github.com/jamesmontemagno/MediaPlugin

Community
  • 1
  • 1
Lucas Zhang
  • 18,630
  • 3
  • 12
  • 22