On Android 13 and later, how does an app get the POST_NOTIFICATIONS permission, and how does its target SDK change when the dialog appears?
answer
- new installs start with alerts off
- manifest entry plus runtime request
- target 33+ chooses the moment
- target 32 or lower: channel triggers it
- areNotificationsEnabled before posting
basics
~20 sPOST_NOTIFICATIONS is a runtime permission from Android 13 (API 33): declare it, then request it. Apps targeting 33+ choose when the dialog appears; for targets of 32 or lower the system shows it once a channel exists and an activity starts.
solid answer
~40 sOn Android 13 (API 33) and later a fresh install starts with notifications off, so the app declares `android.permission.POST_NOTIFICATIONS` in the manifest and requests it like any runtime permission, for example with the `RequestPermission` contract when the user taps a 'Notify me when my wash is done' button. Targeting API 33+ gives the app full control of that moment. Targeting 32 or lower hands it to the system, which shows the dialog when an activity starts after the app has created a channel; one 'Don't allow' then sticks until reinstall or a target bump. Apps already installed before the device upgraded are pre-granted if they had a channel and notifications were on. Before posting I check `ContextCompat.checkSelfPermission(...)` or `NotificationManagerCompat.areNotificationsEnabled()`.
code
kotlin · 19 linesclass VisitActivity : ComponentActivity() {
private val askNotifications =
registerForActivityResult(ActivityResultContracts.RequestPermission()) { granted ->
if (granted) enableMachineAlerts() else showAlertsOffHint()
}
fun onNotifyMeTapped() {
when {
ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) ==
PackageManager.PERMISSION_GRANTED -> enableMachineAlerts()
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU ->
askNotifications.launch(Manifest.permission.POST_NOTIFICATIONS)
else -> startActivity(
Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
)
}
}
}go deeper
Remember that Android 13 added POST_NOTIFICATIONS as a runtime permission, that new installs start with notifications off, and that the manifest entry alone is not enough.
Explain how the target SDK moves control of the dialog between the system and the app, the three dialog outcomes, and which check to run before posting.
Show you handle upgrade pre-grants, users who later turn notifications off, the foreground-service exemption, and that you test each path with adb rather than a reset device.
Frame the request as product timing the team agrees on: ask in context after a clear benefit, measure grant rates, and keep the app useful for users who say no.
## What changed in Android 13 From **Android 13 (API level 33)**, posting non-exempt notifications needs the runtime permission **`POST_NOTIFICATIONS`**, and the notifications of a foreground service count as non-exempt. On a new install the app's notifications are **off by default**: it must declare the permission, ask for it and wait for the grant before anything it posts reaches the shade. ```xml <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> ``` ## Who decides when the dialog appears The target SDK decides who controls the timing: | App targets | When the dialog appears | What a single "Don't allow" means | |---|---|---| | API 33 or higher | Only when the app requests `POST_NOTIFICATIONS` itself | The app may ask again later through the normal runtime-permission flow | | API 32 (12L) or lower | The system shows it the first time an activity starts after the app has created a notification channel, or when an activity starts and then creates its first channel; usually at launch | The user is not prompted again until the app is reinstalled or updated to target 13+ | So targeting 33+ is what lets a laundromat app ask at the moment the request makes sense, when the customer taps "Notify me when it's done", instead of on the first screen. ## The three outcomes of the dialog 1. **Allow**: all channels may post, and foreground-service notifications appear in the drawer. 2. **Don't allow**: every channel is blocked except for exempt cases, just as if the user had switched off all of the app's notifications in settings. 3. **Swipe away** without choosing: the permission state does not change. ## Devices that upgrade to 13 To avoid surprising existing users, the system **pre-grants** the permission to eligible apps when the device upgrades to Android 13, so they keep posting without a prompt. Eligible means the app already had a notification channel and the user had not turned its notifications off on 12L or lower; a user who had turned them off stays off after the upgrade. An app restored from a backup of a 12L device where notifications were allowed is treated the same way. ## Exemptions - Notifications tied to **media sessions** are exempt. - An app that manages its own calls can post call-style notifications without the permission; calling flows are outside this lesson. - A **foreground service** can still start without the permission and must still supply a notification; if the user denied it, the service's notice is visible in the Task Manager but not in the drawer. ## Checking before you post - `NotificationManagerCompat.notify()` is annotated `@RequiresPermission(POST_NOTIFICATIONS)`, so Android lint expects a permission check around it. - `ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS)` works on every release: below API 33 it returns the result of `areNotificationsEnabled()` instead of a manifest grant. - `NotificationManagerCompat.areNotificationsEnabled()` tells you whether the app's notifications are blocked at all, which is also how you notice a user who later switched them off in settings. - For a user who has said no, a settings button can open `Settings.ACTION_APP_NOTIFICATION_SETTINGS` with `Settings.EXTRA_APP_PACKAGE`; the rationale screen and the denial paths of the request itself work as for any runtime permission. ## Rationale and responsible use The guide's recommended flow has a middle explanation screen ("Get notified!") that the app needs only when `shouldShowRequestPermissionRationale()` returns `true`; otherwise it can request straight away from the user's action. The guide's examples of good moments are a tap on an alert bell, following someone, or submitting an order; the design of when to ask is covered with notification delivery design. After the grant, remember that users can see how many notifications the app sends each day and can revoke the permission at any time, so a noisy channel costs you the permission for every channel. ## Testing the paths with adb The documentation gives `adb shell pm revoke` and `pm grant` for `android.permission.POST_NOTIFICATIONS`, combined with `pm set-permission-flags` / `pm clear-permission-flags` for the `user-set` and `user-fixed` flags, to reproduce a fresh install, an upgrade with notifications on, and an upgrade after the user had turned them off, without resetting the device. ## Mistakes that show up in review - Keeping `targetSdkVersion` at 32 and wondering why the dialog appears on the first screen. - Posting without any check and assuming the notification was shown. - Treating a swipe-away as a refusal and never asking again.
- Your app targets API 32 and new Android 13 users see the notification dialog on the splash screen; why, and how do you move it?With a target of 32 or lower the system shows the dialog when an activity starts after the app has created a channel, which is usually at launch. Raising the target to API 33 or higher hands the timing to the app, which can then request `POST_NOTIFICATIONS` when the user asks for alerts. It also avoids the old rule that one 'Don't allow' blocks the prompt until reinstall.
- The user granted the permission months ago but alerts stopped; what do you check?Call `NotificationManagerCompat.areNotificationsEnabled()` to see whether the app's notifications were switched off, then read the specific channel with `getNotificationChannelCompat(id)` and its `getImportance()`, since the user may have blocked only that channel. Offer a settings button rather than re-requesting a permission that is still granted.
- POST_NOTIFICATIONS needs only a manifest entry, no runtime request
- Swiping the dialog away counts as denying the permission
- Apps targeting API 32 never see a notification dialog on Android 13
- A foreground service cannot start until POST_NOTIFICATIONS is granted
- Checking POST_NOTIFICATIONS below API 33 always returns granted
Assumes API 37 and androidx.core 1.19.1; POST_NOTIFICATIONS is a runtime permission from Android 13 (API 33), and the dialog's timing depends on whether the app targets 33 or higher.