Android Notification Runtime Permissions

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.

TypeScript
import { MoECapacitorCore } from 'capacitor-moengage-core'
MoECapacitorCore.pushPermissionResponseAndroid({isGranted: isGranted});

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.

TypeScript
import { MoECapacitorCore } from 'capacitor-moengage-core'
MoECapacitorCore.updatePushPermissionRequestCountAndroid({appId: "YOUR_APP_ID", count : count});

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.

TypeScript
import { MoECapacitorCore } from 'capacitor-moengage-core'
MoECapacitorCore.setupNotificationChannelsAndroid();

Request Permission

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.

TypeScript
import { MoECapacitorCore } from 'capacitor-moengage-core'
MoECapacitorCore.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.

TypeScript
import { MoECapacitorCore } from 'capacitor-moengage-core'
MoECapacitorCore.navigateToSettingsAndroid();

Previous

Next

Was this article helpful?
0 out of 0 found this helpful

How can we improve this article?