Android 13 (API level 33) and higher supports runtime permission for sending non-exempt(including Foreground Services (FGS)) notifications from an app POST_NOTIFICATIONS. This change helps users focus on the notifications that are most important to them.
Refer to the official documentation for more details.
The below-mentioned APIs are supported starting SDK version 12.3.01
When the application is running on Android 13 to show notifications to the user, applications would need to request the user for notification permission.
For applications integrating the MoEngage SDK, would need to
- Notify the SDK of the permission request's response from the user.
- If the application has already requested push permission(before MoEngage integration) help MoEngage set up notification channels for notification display.
Notify SDK of permission result
Once the application requests the user for notification permission notify the SDK of the user response using the below API.
import ReactMoE from 'react-native-moengage' ReactMoE.pushPermissionResponseAndroid(true);
Update the Permission request count
Once the application requests the user for notification permission, update the SDK of the request attempts.
Why does the SDK require permission attempt count?
SDK requires the attempt count to accurately track the number of times the permission request was attempted. If the user denies the permission request twice the application/SDK cannot request permission further i.e. if we request permission it would be automatically denied without the user seeing the request dialog. As an SDK we cannot be sure of the number of times the user has denied the permission we try to optimize the calls to request permission based on the attempt count.
import ReactMoE from 'react-native-moengage' ReactMoE.updatePushPermissionRequestCountAndroid(requestCount);
Setup Notification Channels
If the application has already taken notification permission from the user call the below API to set up Notification Channels for showing push notifications.
import ReactMoE from 'react-native-moengage' ReactMoE.setupNotificationChannelsAndroid()
MoEngage SDK provides helper APIs to show the permission request to the end-user or navigate the user to the settings screen for enabling notifications.
Use the below API to show the permission request dialog to the user.
When using the below API SDK automatically tracks the response, sets up the required notification channel, etc, mentioned above.
import ReactMoE from 'react-native-moengage' ReactMoE.requestPushPermissionAndroid()
Navigate to Notification Settings
Use the below API to show navigate the user to the Notification Settings for the application on the device.
Note: Below Android 8(API level 26) the user is directed to the Application Info screen of your application.
import ReactMoE from 'react-native-moengage' ReactMoE.navigateToSettingsAndroid()