Top Tips for Adopting Android’s Notification Permission

Terence Zhang
Android Developers
Published in
4 min readAug 24, 2022

--

Overview

Excess notifications is a digital-wellbeing problem for users worldwide. In Android 13, we’re helping users take back control of their notification experience by introducing a new runtime permission. Users must grant this permission to an app before that app can post notifications to the notification drawer, including those related to foreground services.

For many apps, Android’s official documentation should have enough information and guidance to onboard your app to handle the new permission. If you are looking for tips to improve your app’s user experience before you target Android 13 or test your app’s integration with the permission without flashing different OS versions onto your device, then you have come to the right place!

Requesting In-Context With Target SDK <= 32

In Android 13, when your app creates its first notification channel, the user sees the notification permission prompt if your app is displaying a user-visible activity. This means that if your app creates its first channel upon launch or while running in the background, then the user sees the prompt immediately after they launch your app.

This sudden prompt may be disruptive to your app’s user journey, and is likely to increase permission denial rates. That’s because new users, who aren’t yet familiar with your app, may not feel comfortable granting access to their personal information. For those reasons, we highly recommend requesting the permission in-context — that is, when they navigate to the appropriate feature. What in-context means varies on a per-app basis, and you can find some ideas in the documentation for runtime permissions.

While it’s much easier to request the permission in-context when your app targets Android 13 (setting targetSdkVersion to 33), apps that target older versions of Android can help the OS request the permission in-context by changing when they create their first notification channels. As mentioned earlier, Android advises you to create your first channel when users are in-context.

You can also start drafting your app’s educational UI to explain why your app needs access to notifications. Our research shows that apps that explain why they need a particular permission tend to get higher opt-in rates.

If your app provides an onboarding flow for new users, you can choose to show the educational UI first, before your app creates its first notification channel and causes the notification permission prompt to appear. Please test this out with your app to verify that the timing makes sense from a new user’s perspective.

Testing Notification Permission

We understand that many of you have asked for easier ways to test your apps’ integration with the Notification Permission feature! We are excited to announce some new adb commands that can help streamline your testing process.

Step 1: Flash the latest version of Android 13 to your device.

Step 2: Set up adb on your device.

Step 3: Find the scenario below that you would like to test and run the relevant adb commands to set your app’s notification permission state.

Note: make sure you change the “com.name.app” to your own app’s package name.

  1. Newly Installed App on Device Running Android 13
adb shell pm revoke com.name.app android.permission.POST_NOTIFICATIONSadb shell pm clear-permission-flags com.name.app android.permission.POST_NOTIFICATIONS user-setadb shell pm clear-permission-flags com.name.app android.permission.POST_NOTIFICATIONS user-fixed

2. Existing App (with notifications enabled by user in legacy OS)

adb shell pm grant com.name.app android.permission.POST_NOTIFICATIONSadb shell pm set-permission-flags com.name.app android.permission.POST_NOTIFICATIONS user-setadb shell pm clear-permission-flags com.name.app android.permission.POST_NOTIFICATIONS user-fixed

3. Existing App (with notifications disabled by user in legacy OS)

adb shell pm revoke com.name.app android.permission.POST_NOTIFICATIONSadb shell pm set-permission-flags com.name.app android.permission.POST_NOTIFICATIONS user-setadb shell pm clear-permission-flags com.name.app android.permission.POST_NOTIFICATIONS user-fixed

General Best Practices When Sending Notifications

Verify Permission Before Sending Notifications:

Verify that users have enabled notifications before you try to send notifications. You can check by first calling the NotificationManager#areNotificationsEnabled() API. After the user upgrades their device to Android 13, the API reflects the user’s response to the notification permission in addition to the notifications toggle in the Settings page. Checking the permission also helps you assess the impact of having your feature depend on a permission (eg. opt-out rates) as well.

Handle Permission Denials:

If notifications are essential for your app and the user denies the permission, you can consider helping users understand the implications of the denial, such as showing an educational UI. In this explanation, mention that they can no longer receive notifications from your app.

Enhancing Support for Channels:

Continue to classify notifications into channels, as it allows users to select what kinds of notifications they want to receive from your app (instead of disabling your app’s notifications outright) and control the visual/auditory behavior for notifications. In addition, use meaningful channel names and descriptions to help users understand the type notifications included in the channel.

--

--

Terence Zhang
Android Developers

Developer Relations Engineer @ Android working on all things privacy