Notifications (original) (raw)

Notifications provide brief, timely, and relevant information related to your app when it's not in use.

The Android OS controls many aspects of notifications, but you have control over other aspects. Follow these steps when implementing notifications:

  1. Understand the anatomy of a notification.
  2. Choose the type of notification for your use case.
  3. Set the notification category that aligns with the type of notification you've chosen.

Takeaways

Anatomy of a notification

Notifications are designed to make it easy to scan and use a notification's most important elements. These elements are:

Figure 1: Collapsed notification

When collapsed, a notification shows the app icon, header text, timestamp, expand indicator, and content text. It can also optionally show a large icon.

1 App icon: The app icon is a two-dimensional representation of your app's identity. It appears in monochrome in the status bar. If your app sends a wide variety of notifications, consider replacing your app icon with a symbol to distinguish between the different kinds of notifications. See Apply the icon color for details.

2 Header text: a brief headline for the notification or source, such as the account name for users. Content is the most prominent element of a notification.

3 Timestamp: indicates when a notification was sent, such as the time of a missed call.

4 Expand indicator: indicates whether the notification is in a collapsed or expanded state.

5 Content text: supporting information.

6 Large icon (optional): An image may be added to reinforce the notification in a meaningful way, such as a message that includes an avatar of the sender.

Apply the icon color

Starting in Android 12 (API level 31), the system derives the icon color from the notification color you set in the app. If the app doesn't set the color, it uses the system theme color. Previously, the color was gray.

Figure 3: Resulting styled app icon color

For most styles, the system applies this color only if the notification is for a foreground service notification. However, there is no such requirement for MediaStyle and DecoratedMediaCustomViewStyle notifications that have a media session attached.

The following snippet shows how to apply the icon color.

val notification = Notification.Builder()
    .setColor(Color.GREEN)
    .setColorized(true)
    .setSmallIcon(R.drawable.app_icon)
    .setStyle(Notification.DecoratedCustomViewStyle())
    .build()

Notification actions

Figure 4: Notification action area

1 Text button actions

2 Filled action buttons

3 Suggested replies

4 Reply text field

Starting with Android 7.0 (API level 24), the system shows actions without icons to accommodate more text. To accommodate Android Wear devices and devices running Android 6.0 (API level 23) and lower, your app must still provide an icon.

Expanded views

You can use an expanded view to display more information to the user without navigating away from the notification.

When expanded, a notification can provide up to three of any of the following kinds of actions:

Don't

Include text actions that duplicate the behavior of tapping on the notification body.

Do

Give the user a chance to interact with the notification. The Google Clock app shows a timer running, but it lets the user pause or add a minute directly from the notification.

Enable typing in notifications

You enable the user to type directly into a notification by including a Reply action. This is designed for typing a small amount of text, such as replying to a text message or jotting a brief note.

For longer-form typing, navigate users to your app to provide them more space to view and edit text.

For messaging apps, we recommend keeping the notification present after the user has sent the reply, and waiting until the conversation is paused before automatically dismissing it.

Figure 5: A user replying directly in the Android Messages without leaving the notification after tapping Reply

Choose the notification type depending on your use case

Google uses the following notification templates in its Android apps. These templates can be customized to some extent for your app.

Check out the Android UI Kit on Figma for notification templates.

Standard template

The standard template is suitable for most notifications, allowing succinct text, a large icon (when applicable), and actions.

Figure 6: Standard notification template

Big text template

The big text template is ideal for displaying blocks of longer text. It lets the user preview more text after they expand the notification.

Figure 7: Big text template, with option large icon

Big picture template

The big picture template is designed for notifications containing an image. When collapsed, the notification shows a large icon thumbnail of the picture. When expanded, the notification shows a much larger preview.

Figure 8: Big picture template

Progress template

The progress template is designed for user-initiated activities that take time to complete. When expanded, a notification that uses this template shows a progress bar and also includes a "cancel" action that lets the user terminate this activity. (Non-cancelable activities don't warrant notifications.)

Figure 9: Progress template

Media template

The media template is designed for letting the user control media currently playing from an app.

Figure 10: Media template

Messaging template

The MessagingStyle template is designed for real-time communication. When expanded, a notification using this template lets the user reply to messages from within the notification.

Figure 11: Messaging template

Call template

Use the CallStyle template to generate large-format notifications that include a large image attachment and indicate an incoming or outgoing call.

Figure 12: Call template

Notification permissions

As relevant and timely as notifications can be, most notifications are_non-exempt_, that is, the user must consent to receiving notifications from your app.

There is one exception to this: starting in Android 13 (API level 33), media sessions and apps that manage phone calls are exempt from asking for user consent. Pre-existing apps may also be eligible if the user already has notifications on. See more details in Exemptions.

We strongly recommend that your app provide notification options in settings to allow users to update their notifications preferences.

Prompt the user to opt-in to non-exempt notifications

For non-exempt notifications, prompt the user to indicate whether they want to to opt-in to receiving notifications. Users who explicitly choose to receive notifications are likely to find them more useful and less intrusive.

Figure 13: Requesting a user's consent for a non-exempt notification

Wait to show the notification dialog prompt:

Starting in Android 13, users can be re-prompted for notification permissions.

Required notifications

Foreground services perform operations that are noticeable to the user but while they're not directly interacting with your app. These services show a status bar notification to make users aware that your app is performing a task in the foreground and is consuming system resources.

Figure 14: Example of fitness app foreground service notification

Because these processes use battery and possibly data, your app must make users aware of them by showing a non-dismissible notification. The user can't dismiss the notification, so you must provide an action for the user to stop the service.

The following example shows a notification from a fitness app. The user has started an active workout session, which instantiates a foreground service tracking the workout session. The app shows the notification to indicate it's tracking walking, with an option to see the workout.

When not to use a notification

Don't use notifications for any of the following use cases:

Don't

Send holiday or birthday greetings in the form of notifications.

Don't

Interrupt the user in the middle of a task for the sole purpose of asking if you're doing a good job.

Behavior

Be aware of the following notification behaviors and how to handle them in certain contexts.

Notification arrival

When a notification arrives, Android adds it to the notification drawer. Depending on the parameters you set and the current state of the device, the notification may perform any of the following actions:

As always, the user can choose to alter the notification behaviors you set.

**Figure 15:**Notification arrival

1 Notification indicator in the status bar, indicating that there's a notification in the notification drawer.

2 Notification "peeking" onto the current screen to grab a user's attention in the middle of a task.

Notification drawer

The notification drawer in Android typically shows notifications in reverse-chronological order, with adjustments influenced by the following conditions:

Handle stale notifications

The notification drawer is designed to show users information that is relevant for the current moment in time. If an earlier notification is stale, that is, no longer relevant, dismiss it so the user doesn't see it.

Figure 16: Just-arrived text appears at the top of the notification drawer, with a lower priority notification about a photo being added at the bottom

New notifications indicated by app icon badge

In supported launchers on devices running Android 8.0 (API level 26) and higher, app icons display a notification dot to indicate that the app has a new notification associated with it. These dots appear by default in launcher apps that support them, and there's nothing your app needs to do. Badging can also be disabled and limited.

Figure 17: Notification dot on an app icon, indicating the app has a new notification associated with it

Actions users can perform with notifications

Notifications can enable users to perform any of the following actions:

Ongoing notifications that indicate a continuing process in the background, such as music playing, may not be dismissed with a swipe.

The controls displayed vary depending on the Android version and whether the app has channels for its notifications (starting in Android 8.0).

Group multiple notifications

For apps that generate multiple notifications of the same type, Android offers notification grouping to avoid overwhelming users.

Your app can present multiple notifications according to the following hierarchy.

Android presents child notifications without duplicate header information. For example, if a child notification has the same app icon as its parent, the child's header doesn't include an icon.

Child notifications must be understandable if they appear solo, as the system may show them outside of the group when they arrive.

Figure 19: Grouped notifications collapsed and expanded views.

Settings

Channels

Starting in Android 8.0 (API level 26), all notifications must be assigned to a channel. For each channel, you can set the visual and auditory behavior that is applied to all notifications in that channel. Users can change these settings and decide which notification channels from your app can be intrusive or visible.

For details on how to implement this, see Create and manage notification channels.

Importance should be chosen with consideration for the user's time and attention. When an unimportant notification is disguised as urgent, it can produce unnecessary alarm.

Importance Behavior Usage Examples
HIGH Makes a sound and appears on screen Time-critical information that the user must know, or act on, immediately Text messages, alarms, phone calls
DEFAULT Makes a sound Information that should be seen at the user’s earliest convenience, but not interrupt what they're doing Traffic alerts, task reminders
LOW No sound Notification channels that don't meet the requirements of other importance levels New content the user has subscribed to, social network invitations
MIN No sound or visual interruption Non-essential information that can wait or isn’t specifically relevant to the user Nearby places of interest, weather, promotional content

Pre-defined categories

Whether you're using channels or not, assign each individual notification to the most suitable predefined category. Android may use this information to make ranking and filtering decisions.

Category Description
CATEGORY_CALL Incoming call (voice or video) or similar synchronous communication request
CATEGORY_MESSAGE Incoming direct message (SMS, instant message, etc.)
CATEGORY_EMAIL Asynchronous bulk message (email)
CATEGORY_EVENT Calendar event
CATEGORY_PROMO Promotion or advertisement
CATEGORY_ALARM Alarm or timer
CATEGORY_PROGRESS Progress of a long-running background operation
CATEGORY_SOCIAL Social network or sharing update
CATEGORY_ERROR Error in background operation or authentication status
CATEGORY_TRANSPORT Media transport control for playback
CATEGORY_SYSTEM System or device status update. Reserved for system use.
CATEGORY_SERVICE Indication of running background service
CATEGORY_RECOMMENDATION A specific, timely recommendation for a single thing. For example, a news app might recommend a news story the user might want to read next.
CATEGORY_STATUS Ongoing information about device or contextual status

Lock screen notifications

If a user has opted to show notifications when their screen is locked, these notifications can conceal any content that your app marks as sensitive. Android evaluates each notification's visibility level to determine what can safely be shown.

Set sensitivity level for content on lock screens

User privacy is critically important, so be aware that there are different levels of notification that can be visible on the lock screen. For each notification you create, you must set the visibility level to public, private, or secret.

In the following example, lock screen notifications for the Gmail and Photos apps show all content after the user has chosen to show this information on the lock screen.

Figure 20: Lock screen with different sensitivity levels.

1 All notification content shown on the lock screen

2 Sensitive notification content hidden on the lock screen

Style

Clear and concise text

Android truncates content titles to a single line (even when expanded).

A good content title adheres to the following guidelines:

Don't

Show the app name in the content title, which is redundant with the header area and uses available characters.

Do

Show the most important information in the content title.

Good content text adheres to the following guidelines:

The large icon

Use the large icon for use cases in which imagery meaningfully reinforces the notification's content. Some examples are:

Large icons must be circular when showing a person, but square in all other cases.

Don't

Use the large icon for branding.

Do

Use the large icon to reinforce a notification's content in a meaningful way, such as a displaying person's photo attached to a message notification.

Android version updates

The Android notification system UI and the notification-related APIs continually evolve. For a list of these changes check out the notification compatibility.

Platform Considerations

Wear

If the user has a paired Wear OS device, all your notifications appear there automatically, including expandable detail and action buttons. For details, see the design page for notifications on Wear.