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?
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);
}
}
}