Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin - Android 13 Notification Permission Prompt

As we know, Android 13 is introducing runtime notification permission. Here's the Android developer documentation on this.

We already have a priming page where we show the notification permission prompt in iOS. We just need to do this for all users on Android 13.

After reading the documentation, i've added the following:

<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

However I can't seem to find a way to prompt Android users. Has anyone had any success with this/can point me in the right direction?

Also, we've noticed all of our users who have upgraded to Android 13 have notifications turned off by default. Is there a way we can add a link to the notifications permission in the settings?

like image 260
tayab Avatar asked Oct 23 '25 11:10

tayab


1 Answers

I am currently using this to achieve that, in your MainActivity put this

protected override void OnStart()
        {
            base.OnStart();
            const int requestLocationId = 0;

            string[] notiPermission =
            {
                Manifest.Permission.PostNotifications
            };

            if ((int)Build.VERSION.SdkInt < 33) return;

            if (this.CheckSelfPermission(Manifest.Permission.PostNotifications) != Permission.Granted)
            {
                this.RequestPermissions(notiPermission, requestLocationId);
            }
        }
like image 99
Eyner Mamani Avatar answered Oct 25 '25 07:10

Eyner Mamani