Atif Rehman
Atif Rehman

Reputation: 1

it does not prompt me for media access permission. (Android 13 API level 33) using xamarin forms

When my target Android version is Android 12.1 (API Level 32), everything works fine.

In Xamarin Android set the target to Android 13 (API 33), but in Android 13, it doesn't prompt me for media access permission.show this error . Set target .

I am trying to update the package, but the package is not getting updated.

Upvotes: 0

Views: 633

Answers (2)

Liyun Zhang - MSFT
Liyun Zhang - MSFT

Reputation: 14594

The READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permission has been removed since android 13.0.

The official document said:

If your app targets Android 13 or higher and needs to access media files that other apps have created, you must request one or more of the following granular media permissions instead of the READ_EXTERNAL_STORAGE permission:

  • READ_MEDIA_IMAGES
  • READ_MEDIA_VIDEO
  • READ_MEDIA_AUDIO

So you can use the android native code about permision request to do that. Such as:

if(AndroidX.Core.App.ActivityCompat.CheckSelfPermission(Xamarin.Essentials.Platform.CurrentActivity, Android.Manifest.Permission.ReadMediaImages) != Permission.Granted)
{
    AndroidX.Core.App.ActivityCompat.RequestPermissions(Xamarin.Essentials.Platform.CurrentActivity, new string[] { Android.Manifest.Permission.ReadMediaImages }, 100);
}

Upvotes: 0

dembo
dembo

Reputation: 93

The NuGet package your are trying to use (Xam.Plugin.Media) has been archieved in December 2020

This library has a lot of legacy code that is extremely hard to maintain and update to support the latest OSes without a major re-write. I will officially be archiving this library in December 2020 unless anyone from the community wants to adopt the project.

You should be using instead Xamarin Essentials.

There is an open issue for what you are facing. Right now there is not much more to do. I just target Android 12.1 until they fix it.

Upvotes: 0

Related Questions