החל מ-27 במרץ 2025, מומלץ להשתמש ב-android-latest-release
במקום ב-aosp-main
כדי ליצור תרומות ל-AOSP. מידע נוסף זמין במאמר שינויים ב-AOSP.
הרשאה לשליחת התראות על הבעת הסכמה
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
ההתראות ב-Android 13 מבוססות על מודל הסכמה מראש, בניגוד לגרסאות קודמות של Android שבהן נעשה שימוש במודל ביטול הסכמה. ב-Android 13, כל האפליקציות צריכות לבקש מהמשתמשים הרשאה לפני שליחת הנחיות לגבי התראות. המודל הזה עוזר לצמצם את ההפרעות מהתראות, מפחית את עומס המידע ומאפשר למשתמשים לקבוע אילו התראות יופיעו על סמך מה שחשוב להם. כדי לתמוך במודל ההסכמה מראש, יצרני ציוד מקורי צריכים להטמיע שינויים במערכות ההתראות וההרשאות בסביבת זמן הריצה.
בדף הזה מוסבר מה יצרני ציוד מקורי צריכים להטמיע כדי לתמוך בשינוי הזה, ואיך מאמתים את ההטמעה.
הטמעת שינויים בהתראות לגבי הסכמה לקבלת הודעות
החל מ-Android 13, אפליקציות צריכות להצהיר על הכוונה שלהן לשלוח התראות על ידי בקשה מהמערכת להרשאת זמן ריצה android.permission.POST_NOTIFICATION
, לפני שהן יכולות לשלוח התראות.
ב-Android 13 ואילך, ההגדרה שקובעת אם אפליקציה יכולה לשלוח התראות למשתמש מאוחסנת במערכת ההרשאות.
לפני Android 13, ההגדרה הזו נשמרה במערכת ההתראות. לכן, יצרני ציוד מקורי (OEM) צריכים להעביר את נתוני ההתראות הקיימים לגבי האפליקציות שמותר להן לשלוח התראות, ממערכת ההתראות למערכת ההרשאות בסביבת זמן הריצה. יצרני ציוד מקורי צריכים גם לתחזק ממשקי API קיימים במערכת ההתראות שמציגים את הנתונים האלה למפתחי האפליקציות.
השינויים במערכות ההתראות וההרשאות מבוססים על מודל ההסכמה של התנהגות ההתראות של המשתמשים, ומתוארים בקטע הנחיות להטמעה.
ההתנהגות של התראות למשתמשים במודל של הסכמה מראש
בטבלה הבאה מוסבר איך ההתראות פועלות בגרסאות שונות של האפליקציה במכשיר עם Android 13:
מכשיר עם Android 13 |
אפליקציות שמטרגטות ל-Android מגרסה 13 ואילך |
אפליקציות שמטרגטות גרסאות ישנות יותר מ-Android 13 |
התקנה חדשה
|
ההתראות נחסמות עד שתופיע בקשה מהאפליקציה.
האפליקציות קובעות מתי לבקש הרשאה.
|
ההתראות נחסמות עד שמופיעה בקשה מהמערכת.
בקשת ההרשאה מופיעה בפעם הראשונה שמפעילים את האפליקציה.
|
אפליקציה קיימת (שדרוג)
|
ההתראות יתקבלו עד שתופיע בקשה מהאפליקציה.
ההרשאה הזמנית ניתנת עד שהאפליקציה מבקשת אותה בהפעלה הראשונה שעומדת בדרישות.
|
ההתראות מותרות עד שמופיעה בקשה מהמערכת.
ההרשאה הזמנית ניתנת עד להפעלה הראשונה של האפליקציה.
|
הנחיות להטמעה
להטמעה של הפניות, אפשר לעיין במאמרים בנושא שירות התראות, שירות הרשאות ושירות מדיניות. במאמר הרשאות בזמן ריצה מוסבר איך מטמיעים חריגים ל-handlers של הרשאות ברירת המחדל.
במהלך ההטמעה, מומלץ להשתמש בהנחיות הבאות לגבי התנהגות ההתראות למשתמשים באפליקציות שמטרגטות SDK של Android מגרסה 13 ומטה:
- אפליקציות שהותקנו לאחרונה במכשיר עם Android 13 לא יכולות לשלוח התראה בלי שהמשתמש יאשר בקשה להרשאה.
- אם האפליקציה מטרגטת את הגרסאות Android 13 ואילך, צריך לחסום את ההתראות עד שתופיע בקשה מהאפליקציה, כי האפליקציה קובעת מתי ובאיזה מקרה לבקש מהמשתמשים הרשאה.
- אם האפליקציה מטרגטת גרסאות ישנות יותר מ-Android 13, צריך לחסום את ההתראות עד שתופיע בקשה ממערכת ההפעלה. מערכת ההפעלה חייבת להציג את בקשת ההרשאה בהפעלה הראשונה של האפליקציה.
כל אפליקציה שהיתה במכשיר לפני השדרוג ל-Android 13, או כל אפליקציה ששוחזרה באמצעות גיבוי ושחזור, חייבת לקבל הרשאה לשלוח התראות עד שהמשתמש יפעיל פעילות מהאפליקציה הזו בפעם הראשונה.
באפליקציות שמטרגטות SDK בגרסאות Android 13 ואילך, אם המשתמש לא התאים אישית בעבר את הגדרות ההתראות של האפליקציה הזו ברמת האפליקציה או ברמת NotificationChannel
, צריך לבטל את מתן ההרשאה הזמנית. לאחר מכן, האפליקציות יצטרכו לבקש מהמשתמשים הרשאה כדי להמשיך לשלוח התראות.
אם לאפליקציה משודרגת שמטרגטת את Android 13 אין כרגע הרשאת התראות באמצעות ההרשאה הזמנית לשדרוג, והמשתמש הפעיל אותה לפחות פעם אחת, האפליקציה חייבת להציג בקשה להרשאת התראות לפני שתהיה לה אפשרות להפעיל שירותים נוספים בחזית.
באפליקציות עם גרסה של Target SDK נמוכה מ-Android 13, צריך לעצור את ההפעלה הראשונה של הפעילות אחרי שהאפליקציה יצרה לפחות אירוע NotificationChannel
אחד, כדי להציג בקשה לקבלת הרשאה שבה המשתמש יתבקש לבחור אם הוא רוצה לקבל התראות מהאפליקציה.
אם משתמש התאים אישית בעבר את הגדרות ההתראות ברמת האפליקציה או ברמת NotificationChannel
לאפליקציה במכשיר לשדרוג או בגיבוי שמושחזר למכשיר, צריך להעביר את ההגדרה ברמת האפליקציה למערכת ההרשאות באמצעות הדגל FLAG_PERMISSION_USER_SET
. אסור להציג למשתמש בקשה נוספת להרשאת התראות, אלא אם האפליקציה מבקשת זאת במפורש.
הגיבוי והשחזור חייבים להיות תואמים לאחור ולפנים בין מכשיר Android 13 לבין מכשיר מגרסה קודמת של מערכת ההפעלה. נתוני גיבוי שנוצרו במכשיר עם Android 13 צריכים להיות משוחזרים בגרסה קודמת של מערכת ההפעלה, ונתוני גיבוי שנוצרו בגרסה קודמת של מערכת ההפעלה צריכים להיות משוחזרים במכשיר עם Android 13.
התראות מדיה שמשויכות להפעלת מדיה פעילה חייבות להיות פטורות מההרשאה לשליחת התראות.
אימות שינויים במערכות ההתראות וההרשאות
כדי לאמת את ההטמעה, מריצים את הבדיקות הבאות:
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-27 (שעון UTC).
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 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/)."]]