0

Goal: Google Play Console is requiring me to update my app to Android 13. My app is Xamarin.Android

Problem: When I update the Manifest to TargetSdk 33, I am no longer able to access images from the gallery. It does not ask for permissions anymore

It was on targetSdkVersion 31, and I updated it to:

android:targetSdkVersion="33"

What I've tried:

I have tried making sure the Manifest file has the permissions as per: https://developer.android.com/about/versions/13/behavior-changes-13#granular-media-permissions Android API 33 permissions are not granted

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />

I also tried updating in SDK manager, its able to download, but unable to install the system images for API 33. It says "Object reference not set to an instance of an object" This mentions to click Show Details but I don't see that option in the installer anywhere. Error while downloading google APIs Intel x86 atom system image

I've also tried going through the debugger with breakpoints, and using logcat, but I don't see any errors.

I'm stuck at this point. What else could I be missing?

angleUr
  • 449
  • 1
  • 8
  • 27
  • 1
    Are you asking for all of the permissions in the runtime? READ_MEDIA_IMAGES is a dangerous permission, as stated in documetation, so it must be requested in runtime. There is a guide for handling runtime permissions: https://developer.android.com/training/permissions/requesting – Daniil Aug 30 '23 at 16:42
  • I'm just trying to upgrade to Android 13, but issues occurred when I did – angleUr Aug 30 '23 at 16:49
  • 1
    One of the changes is adding READ_MEDIA_IMAGES permission. This permission must be requested in runtime, which could be the cause of your problem. This permission won't be requested automatically – Daniil Aug 30 '23 at 17:07
  • @Daniil The article mentions checking Manifest.Permission. I see in my Activity I already have : PermissionNeeded.Add(Manifest.Permission.ReadExternalStorage) Since READMEDIAIMAGES is new, I figured I should add that in the activity as well. But when I try to do Manifest.Permission.ReadMediaImages it doesn't exist. – angleUr Aug 30 '23 at 20:02
  • you should try Manifest.Permission.READ_MEDIA_IMAGES or android.permission.READ_MEDIA_IMAGES – Daniil Aug 30 '23 at 21:01

1 Answers1

0

You can try to update your visual studio and make the android sdk be a newer version. I used the Visual Studio 2022 17.6.5 and the following code can request the image permission on the android 13.0:

In the MainActivity:

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);
           if (ActivityCompat.CheckSelfPermission(this, Android.Manifest.Permission.ReadMediaImages) != Android.Content.PM.Permission.Granted)
            {
                if ((int)Android.OS.Build.VERSION.SdkInt > 32)
                {
                    AndroidX.Core.App.ActivityCompat.RequestPermissions(
              Xamarin.Essentials.Platform.CurrentActivity, new string[] { Android.Manifest.Permission.ReadMediaImages }, 101);
                }
                else
                {
                    AndroidX.Core.App.ActivityCompat.RequestPermissions(
               Xamarin.Essentials.Platform.CurrentActivity, new string[] { Android.Manifest.Permission.ReadExternalStorage }, 101);

                }
            }
        }
Liyun Zhang - MSFT
  • 8,271
  • 1
  • 2
  • 14