Notifications.requestPermissionsAsync() not show prompt to user - react native

904 Views Asked by At

i am facing problem related to requestPermissionAsync this method does not show prompt to the user. Any help would be highly appreciated

Android Version: 12 Expo SDK: 47

1

There are 1 best solutions below

0
220bytes On

I'm having the same problem on android 12 and expo SDK 48. Here's something from the android developer docs to keep in mind :

"Notifications in Android 13 use an opt-in model, which is a change from previous Android versions, which use an opt-out model. In Android 13, all apps must ask users for permission before sending notification prompts." Find that here

This implies that on all android versions below 13, all newly installed apps are automatically granted notification 'permissions' when they are installed. This remains so until users opt out of receiving notifications from the app. You can check and see, any app you install is automatically allowed to send notifications on android versions below 13.

This means that given the design of the OS, you don't have to ask for it again. If you still do anyways, it still does not show up. Here's why :

"Starting with Android 13, apps must declare their intent to send notifications by requesting the android.permission.POST_NOTIFICATION runtime permission from the system before they can send notifications. In Android 13 and higher, the setting that determines if an app can send notifications to the user is stored in the permission system. Prior to Android 13, this setting was stored in the notification system." Developer docs reference

So when you try requesting notification permissions with the permissions system, as is done with expo and many other platforms, the phone does nothing if its android 13 and below because you're asking for something it doesn't have for you, a notifications 'permission'. Thus requestPermissionsAsync() does nothing with those versions.

Lastly, information from android developer docs indicates that the only way to allow permissions again is if the user manually does so. Otherwise, developers can't request it again from the app. See that here

It may thus be good to include a brief explanation of why users should allow your app notification permissions so that if they should ever disable it, they are likely to be reminded and thus grant it to the app again.