Mulai 27 Maret 2025, sebaiknya gunakan android-latest-release
, bukan aosp-main
, untuk mem-build dan berkontribusi pada AOSP. Untuk mengetahui informasi selengkapnya, lihat Perubahan pada AOSP.
Izin notifikasi untuk notifikasi keikutsertaan
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Notifikasi di Android 13 menggunakan model keikutsertaan, yang
merupakan perubahan dari versi Android sebelumnya, yang menggunakan model keikutsertaan. Di
Android 13, semua aplikasi harus meminta izin pengguna sebelum
mengirim perintah notifikasi. Model ini membantu mengurangi gangguan
notifikasi, meminimalkan kelebihan informasi, dan membantu pengguna mengontrol notifikasi
yang muncul berdasarkan hal yang penting bagi mereka. Untuk mendukung
model keikutsertaan, OEM harus menerapkan perubahan pada sistem notifikasi dan izin
runtime.
Halaman ini menjelaskan hal yang harus diterapkan OEM untuk mendukung perubahan ini dan cara
memvalidasi penerapannya.
Mengimplementasikan perubahan untuk notifikasi keikutsertaan
Mulai Android 13, aplikasi harus mendeklarasikan
intent untuk mengirim notifikasi dengan meminta
izin runtime
android.permission.POST_NOTIFICATION
dari sistem sebelum dapat mengirim notifikasi.
Di Android 13 dan yang lebih baru, setelan yang menentukan
apakah aplikasi dapat mengirim notifikasi kepada pengguna disimpan di sistem izin.
Sebelum Android 13, setelan ini disimpan di
sistem notifikasi. Oleh karena itu, OEM harus memigrasikan data notifikasi yang ada
tentang apakah aplikasi diizinkan untuk mengirim notifikasi, dari sistem
notifikasi ke sistem izin runtime. OEM juga harus mempertahankan API yang ada
dalam sistem notifikasi yang menampilkan data tersebut kepada developer aplikasi.
Perubahan pada sistem notifikasi dan izin didasarkan pada
model keikutsertaan perilaku notifikasi pengguna dan
dijelaskan di bagian Panduan penerapan.
Perilaku notifikasi pengguna dalam model keikutsertaan
Tabel berikut mengilustrasikan perilaku notifikasi untuk berbagai versi
aplikasi di perangkat yang menjalankan Android 13:
Perangkat yang menjalankan Android 13 |
Aplikasi yang menargetkan Android 13 atau yang lebih baru |
Aplikasi yang menargetkan versi yang lebih rendah dari Android 13 |
Penginstalan baru
|
Notifikasi diblokir hingga diminta oleh aplikasi.
Aplikasi mengontrol kapan harus meminta izin.
|
Notifikasi diblokir hingga diminta oleh OS.
Izin diminta saat aplikasi dijalankan untuk pertama kalinya.
|
Aplikasi yang sudah ada (upgrade)
|
Notifikasi diizinkan hingga diminta oleh aplikasi.
Izin sementara diberikan hingga aplikasi meminta izin pada operasi kualifikasi pertama.
|
Notifikasi diizinkan hingga diminta oleh OS.
Izin sementara diberikan hingga aplikasi dijalankan pertama kali.
|
Panduan untuk penerapan
Untuk implementasi referensi, lihat
layanan notifikasi,
layanan izin, dan
layanan kebijakan. Untuk menerapkan pengecualian
untuk pengendali izin default, lihat
Izin Runtime.
Selama penerapan, gunakan panduan berikut tentang perilaku notifikasi
pengguna untuk aplikasi yang menargetkan SDK Android 13 atau yang lebih rendah:
- Aplikasi yang baru diinstal di perangkat Android 13 tidak boleh
mengirim notifikasi tanpa pengguna menyetujui permintaan izin.
- Jika aplikasi menargetkan versi Android 13 dan
yang lebih tinggi, notifikasi harus diblokir hingga diminta oleh aplikasi karena aplikasi
mengontrol kapan dan apakah akan meminta izin pengguna.
- Jika aplikasi menargetkan versi yang lebih rendah dari
Android 13, notifikasi harus diblokir hingga
diminta oleh OS. OS harus menampilkan permintaan izin saat aplikasi pertama kali dijalankan.
Setiap aplikasi yang ada di perangkat sebelum upgrade ke
Android 13, atau aplikasi apa pun yang dipulihkan melalui pencadangan
dan pemulihan, harus diizinkan untuk mengirim notifikasi hingga pertama kali pengguna
meluncurkan aktivitas dari aplikasi tersebut.
Untuk aplikasi yang menargetkan SDK versi Android 13
dan yang lebih tinggi, jika pengguna sebelumnya belum menyesuaikan setelan notifikasi untuk
aplikasi ini di tingkat aplikasi atau NotificationChannel
, cabut pemberian izin sementara. Selanjutnya, aplikasi harus meminta izin pengguna sebelum
diizinkan untuk terus mengirim notifikasi.
Jika aplikasi yang diupgrade yang menargetkan Android 13 saat ini
tidak memiliki izin notifikasi melalui pemberian upgrade
sementara, dan pengguna telah meluncurkannya setidaknya sekali, aplikasi harus menampilkan
permintaan izin notifikasi sebelum diizinkan untuk menjalankan layanan
latar depan lebih lanjut.
Untuk aplikasi yang memiliki versi SDK target yang lebih rendah dari
Android 13,
intersep
peluncuran aktivitas pertama setelah aplikasi membuat setidaknya satu NotificationChannel
untuk menampilkan perintah izin yang menanyakan apakah pengguna ingin menerima notifikasi
dari aplikasi.
Jika pengguna sebelumnya menyesuaikan setelan notifikasi di
level aplikasi atau NotificationChannel
untuk aplikasi di perangkat yang diupgrade atau dalam
pencadangan yang dipulihkan ke perangkat, setelan level aplikasi harus dimigrasikan ke
sistem izin dengan flag FLAG_PERMISSION_USER_SET
. Tidak ada permintaan izin notifikasi
lebih lanjut yang harus ditampilkan kepada pengguna, kecuali jika aplikasi
meminta secara khusus.
Pencadangan dan pemulihan harus kompatibel dengan versi lama dan baru antara
perangkat Android 13 dan perangkat dari versi OS
sebelumnya. Data cadangan yang dihasilkan dari perangkat Android 13
harus dipulihkan ke versi OS sebelumnya, dan data cadangan dari versi OS
sebelumnya harus dipulihkan ke perangkat Android 13.
Notifikasi media yang terkait dengan pemutaran media yang sedang berlangsung harus dikecualikan
dari izin notifikasi.
Memvalidasi perubahan pada sistem notifikasi dan izin
Untuk memvalidasi penerapan, jalankan pengujian berikut:
Konten dan contoh kode di halaman ini tunduk kepada lisensi yang dijelaskan dalam Lisensi Konten. Java dan OpenJDK adalah merek dagang atau merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-07-27 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-07-27 UTC."],[],[],null,["# Notification permission for opt-in notifications\n\nNotifications in Android 13 use an opt-in model, which\nis a change from previous Android versions, which use an opt-out model. In\nAndroid 13, all apps must ask users for permission before\nsending notification prompts. This model helps reduce notification\ninterruptions, minimizes information overload, and helps users control what\nnotifications appear based on what's important to them. To support the\nopt-in model, OEMs must implement changes in the notification and runtime\npermission systems.\n\nThis page describes what OEMs must implement to support this change and how\nto validate the implementation.\n\nImplement changes for opt-in notifications\n------------------------------------------\n\nStarting with Android 13, apps must declare their\nintent to send notifications by requesting the\n[`android.permission.POST_NOTIFICATION`](https://developer.android.com/about/versions/13/changes/notification-permission)\nruntime permission from the system before they can send notifications.\n\nIn Android 13 and higher, the setting that determines\nif an app can send notifications to the user is stored in the permission system.\nPrior to Android 13, this setting was stored in the\nnotification system. Hence, OEMs must migrate the existing notification data\nabout whether an app is allowed to send notifications, from the notification\nsystem into the runtime permission system. OEMs must also maintain existing APIs\nin the notification system that surface that data to app developers.\n\nChanges to the notification and permission systems are based on the\n[opt-in model of user notification behavior](#behavior-optin) and are\ndescribed in the [Guidelines for implementation](#guidelines-impl) section.\n\n### Behavior of user notifications in an opt-in model\n\nThe following table illustrates the notification behavior for various app\nversions on a device running Android 13:\n\n| Device on Android 13 | Apps targeting Android 13 or higher | Apps targeting versions lower than Android 13 |\n|------------------------|--------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|\n| New install | Notifications are blocked until prompted by the app. Apps control when to ask for permission. | Notifications are blocked until prompted by the OS. Permission is asked on the first run of the app. |\n| Existing app (upgrade) | Notifications are allowed until prompted by the app. Temporary permission is granted until the app asks on the first qualifying run. | Notifications are allowed until prompted by the OS. Temporary permission is granted until the first run of the app. |\n\n### Guidelines for implementation\n\nFor reference implementation, refer to\n[notification service](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/services/core/java/com/android/server/notification/),\n[permission service](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/services/core/java/com/android/server/pm/permission/) and\n[policy service](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/services/core/java/com/android/server/policy). To implement exceptions\nfor default permission handlers see\n[Runtime Permissions](/docs/core/permissions/runtime_perms#integration).\n\nDuring implementation, use the following guidelines on user notification\nbehavior for apps targeting Android 13 or lower SDKs:\n\n- Freshly installed apps on an Android 13 device must not send a notification without the user approving a permission prompt.\n - If the app targets versions Android 13 and higher, notifications must be blocked until prompted by the app as the app controls when and if to ask for user permission.\n - If the app targets versions lower than Android 13, notifications must be blocked until prompted by the OS. The OS must show the permission prompt on the first run of the app.\n- Any app that existed on the device prior to an upgrade to\n Android 13, or any app that was restored through backup\n and restore, must be allowed to send notifications until the first time the user\n launches an activity from that app.\n\n - For apps that target SDK of versions Android 13\n and higher, if the user hasn't previously customized notification settings for\n this app at the app or `NotificationChannel` level, revoke the temporary\n permission grant. Apps must then ask the user for permission before being\n allowed to continue to send notifications.\n\n If an upgraded app targeting Android 13 doesn't\n currently have the notification permission through the temporary upgrade\n grant, and the user has launched it at least once, the app must show a\n notification permission prompt before it's allowed to run any further foreground\n services.\n - For apps that have a target SDK of versions lower than\n Android 13,\n [intercept](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/services/core/java/com/android/server/wm/ActivityInterceptorCallback.java)\n the first activity launch after the app has created at least one `NotificationChannel`\n to show a permission prompt asking if the user wants to receive notifications\n from the app.\n\n If a user previously customized notification settings at the\n app or `NotificationChannel` level for an app on the upgrading device or in a\n backup being restored to the device, the app level setting must be migrated into\n the permission system with the `FLAG_PERMISSION_USER_SET` flag. No further\n notification permission prompt must be shown to the user unless the app\n specifically asks it to be.\n- Backup and restore must be backward and forward compatible between an\n Android 13 device and a device from an earlier OS\n version. Backup data generated from an Android 13\n device must restore onto an earlier OS version, and backup data from an earlier\n OS version must restore onto an Android 13 device.\n\n- Media notifications associated with ongoing media playback must be exempt\n from the notification permission.\n\nValidate changes to the notification and permission systems\n-----------------------------------------------------------\n\nTo validate the implementation, run the following tests:\n\n- Unit tests as specified in [`PreferencesHelperTest`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java),\n [`NotificationManagerServiceTest`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java).\n\n- Any manual test that tests upgrades and backup and restore.\n\n- Any CTS Permission and Notification system test that sends notifications.\n Some of these tests are located in [cts/tests/tests/permission/](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/modules/Permission/tests/cts/permission/src/android/permission/cts/),\n [NotificationManagerTest.java](https://cs.android.com/android/platform/superproject/+/android-latest-release:cts/tests/tests/notification/src/android/app/notification/current/cts/NotificationManagerTest.java?q=NotificationManagerTest.java),\n and [cts/tests/tests/notificationlegacy/](https://cs.android.com/android/platform/superproject/+/android-latest-release:cts/tests/tests/notificationlegacy/)."]]