Agent Wranglers

MOB-51Required

Request the system notification permission before you rely on notifications

The app asks for the system notification permission after a clear action and reads the current setting at each start. Important messages also show inside the app. Android builds declare POST_NOTIFICATIONS.

How to do it

Android 13, API level 33, made notifications a runtime permission, and they are off for new installs. An app that never asks sends nothing, and order or security alerts vanish without an error. Apps that target API level 33 or later choose when the dialog shows. Older targets get it on the first screen after a notification channel exists, before people know why. Media sessions and calls the app manages itself are exempt. Foreground service notices then show only in the Task Manager. On iOS, requestAuthorization shows the prompt once. The .provisional option, from iOS 12, skips the prompt and delivers quietly to Notification Center. People then keep or turn off those notifications from the notification itself. Use provisional for low-urgency updates and the full prompt after an action such as "Tell me when my order ships". The timing follows ask for permission after a clear action. Read areNotificationsEnabled() or getNotificationSettings() at each start, and send a one-time code or security alert by another channel when they are off.

Examples

Kotlin example

private val askNotifications = registerForActivityResult(ActivityResultContracts.RequestPermission()) { granted ->
    if (!granted) showInboxHint()
}

fun onNotifyMeTapped() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) askNotifications.launch(Manifest.permission.POST_NOTIFICATIONS)
}

fun canNotify() = NotificationManagerCompat.from(context).areNotificationsEnabled()

Plain text example

func startQuietUpdates() async throws {
    _ = try await UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .provisional])
}

func onNotifyMeTapped() async throws {
    let granted = try await UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge])
    if !granted { showInboxHint() }
}

How to check

On a fresh Android 13 install and a fresh iOS install, no notification prompt shows before the first screen. The prompt shows after the alert control is tapped. After a no, the same message appears in the in-app inbox, and the merged Android manifest lists POST_NOTIFICATIONS.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/mobile-apps/privacy-declarations/notification-permission">Agent Wranglers mobile apps playbook</a>. In code you write, add a comment next to it with the same link.