Notification permissions in Android 13

Android 13 Preview 2

Last weekend I finally got some time to have a play with the Android 13 emulator and I have to admit, its a bit rough around the edges.

For example all the icons in the launcher are humongo 😮

Android 13 icons

Anyway nothing ventured, nothing gained I figured.

Notifications and runtime permissions.

The main goal I had in mind when I downloaded the new emulator was checking out the shiny new POST_NOTIFICATIONS permission being introduced in Android 13.

So, what is it?

Well, iOS has had it for a while and essentially it is a permission prompt for Android apps targeting Android 13 (SDK level 33 and above) asking the user whether they want to receieve notifications. I think this is a great win not only for user experience, but also a win from the privacy perspective.

Anyway, here’s how I went about testing it 📝

  • Downloading Android 13 (Codename Tiramisum) from the SDK manager.
  • In my app’s build.gradle changing the compileSdkVersion to android-Tiramisu and targetSdkVersion to Tiramisu.
  • Downloading Android Studio Dolphin Canary 7.
  • Downloading Android build tools version 33.0.0 rc2 and updating the buildToolsVersion in my app’s build.gradle to 33.0.0-rc2
  • Downloading the emulator arm64-v8a image for Android Tiramisu in the emulator creation wizard in Android Studio.

Ok, now we’re cooking with gas 🔥

Because this is a runtime permission, you also need to follow the general steps 📝

  • Call the checkSelfPermission API for POST_NOTIFICATIONS,
  • If this does not return PERMISSION_GRANTED,
  • Then check if the permission rationale (ie. why you need this permission) dialog.
  • If it returns false, you can call requestPermissions for POST_NOTIFICATIONS directly.
  • If in the the permission rationale dialog, the user clicks the positiveButton, call requestPermissions for POST_NOTIFICATIONS.
        if (Build.VERSION.SDK_INT >= 33) {
            String[] permission = {POST_NOTIFICATIONS};
            if (checkSelfPermission(POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
                if (!shouldShowRequestPermissionRationale(POST_NOTIFICATIONS)) {
                    requestPermissions(permission, 1001);
                } else {

Here’s what it looks like 👌

This post is licensed under CC BY 4.0 by the author.