Skip to content

Most visited

Recently visited

navigation

Notification Changes in Android Wear 2.0

Important: The Wear 2.0 preview is over. Please see the main Android Wear documentation.

Android Wear 2.0 updates the visual style and interaction paradigm of notifications as well as introduces expanded notifications, which provide substantial additional content and actions in an app-like experience.

The visual and interaction changes make it much easier for users to read and interact with notifications from your app. Expanded notifications enable you to deliver Wear users an app-like experience even if you haven't built an Android Wear app.

Note: When developing for Wear 2.0, ensure that you have the latest version of the Android Wear app on your phone.

Visual Updates

Notifications receive important visual updates in Wear 2.0, with material design visual changes.

Figure 1. Comparison of the same notification in Android Wear 1.x and 2.0.

Some of the visual updates include:

Inline Action

Wear 2.0 now supports inline action, which allows users to take actions on a notification from within the notification stream card. On Wear, the inline action appears as an additional button displayed at the bottom of the notification.

Inline actions are optional but recommended for cases in which users are likely to take an action on a notification after viewing the contents in the notification stream card (without going to the expanded notification). Examples of good use cases for inline action on a notification include: replying to a text message, stopping a fitness activity, and archiving an email message.

A notification can provide only one inline action. To display the inline action as an additional button in the notification, set the setHintDisplayActionInline() method to true. When a user taps the inline action, the system invokes the intent that you specified in the notification action.

Adding an inline action

The following code example shows how to create a notification with an inline reply action:

  1. Create an instance of RemoteInput.Builder that you can add to your notification action. This class's constructor accepts a string that the system uses as the key for the text input. Later, your app uses that key to retrieve the text of the input.
    String[] choices = context.getResources().getStringArray(R.array.notification_reply_choices);
        choices = WearUtil.addEmojisToCannedResponse(choices);
      RemoteInput remoteInput = new RemoteInput.Builder(Intent.EXTRA_TEXT)
            .setLabel(context.getString(R.string.notification_prompt_reply))
            .setChoices(choices)
            .build();
    
  2. Use the addRemoteInput() method to attach the RemoteInput object to an action.
    NotificationCompat.Action.Builder actionBuilder = new NotificationCompat.Action.Builder(
            R.drawable.ic_full_reply, R.string.notification_reply, replyPendingIntent);
        actionBuilder.addRemoteInput(remoteInput);
        actionBuilder.setAllowGeneratedReplies(true);
    
  3. Add a hint to display the reply action inline, and use the addAction method to add this action to the notification.
    // Android Wear 2.0 requires a hint to display the reply action inline.
        Action.WearableExtender actionExtender =
            new Action.WearableExtender()
                .setHintLaunchesActivity(true)
                .setHintDisplayActionInline(true);
        wearableExtender.addAction(actionBuilder.extend(actionExtender).build());
    

Expanded Notifications

Android Wear 2.0 introduces expanded notifications, which provide substantial additional content and actions for each notification.

When you specify additional content pages and actions for a notification, those are available to the user within the expanded notification. Each expanded notification follows Material Design for Android Wear, so the user gets an app-like experience.

Expanded notifications

If the first action in the expanded notification has a RemoteInput (e.g., a Reply action), then the choices you set with setChoices() appear within the expanded notification below the first action.

The user can view the expanded notification by tapping on a notification when either of the following is true:

Best practices for expanded notifications

To decide when to use expanded notifications, follow these guidelines:

Adding expanded notifications

Expanded Notifications allow you to include additional content and actions for a notification. You choose the level of detail that your app's notifications will provide; however be judicious with the amount of detail you include in a notification.

Adding additional content

To show additional content in your expanded notification, see Adding Pages to a Notification.

Additional content pages are stacked vertically in the expanded notification and appear in the order they were added. These additional content pages can optionally use a style such as BigTextStyle or BigPictureStyle.

Primary action

The expanded notification will contain one primary action, which is the first action in the notification unless a different action is specified using setContentAction().

Additional actions

To specify additional actions, use addAction() or addActions(). The action drawer of the expanded notification contains all available actions.

MessagingStyle

If you have a chat messaging app, your notifications should use NotificationCompat.MessagingStyle, which is new in Android 7.0. Wear 2.0 uses the chat messages included in a MessagingStyle notification (see addMessage()) to provide a rich chat app-like experience in the expanded notification.

Note: MessagingStyle expanded notifications require that you have at least version 1.5.0.2861804 of the Android Wear app on your paired Android phone.

Smart Reply

Wear 2.0 also introduces Smart Reply for MessagingStyle notifications. Smart Reply provides the user with contextually relevant, touchable choices in the expanded notification and in RemoteInput. These augment the fixed list of choices that the developer provides in RemoteInput using the setChoices() method.

Smart Reply provides users with a fast (single tap), discreet (no speaking aloud), private (messages received by a user never leave the watch), and reliable (no internet connection needed) way to respond to chat messages.

Smart Reply responses are generated by an entirely on-watch machine learning model using the context provided by the MessagingStyle notification. No user notification data is sent to Google servers to generate Smart Reply responses.

To enable Smart Reply for your notification action, you need to do the following:

  1. Use NotificationCompat.MessagingStyle.
  2. Call the method setAllowGeneratedReplies(true) for the notification action.
  3. Ensure that the notification action has a RemoteInput (where the responses will reside).

The following example shows how to create a MessagingStyle notification with Smart Reply responses.

// Create an intent for the reply action
Intent replyIntent = new Intent(this, ReplyActivity.class);
PendingIntent replyPendingIntent =
 PendingIntent.getActivity(this, 0, replyIntent,
  PendingIntent.FLAG_UPDATE_CURRENT);

// Create the reply action and add the remote input
NotificationCompat.Action action =
 new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon,
  getString(R.string.label), replyPendingIntent)
 .addRemoteInput(remoteInput)

// 1) allow generated replies
.setAllowGeneratedReplies(true)
 .build();

Notification noti = new NotificationCompat.Builder()
 .setContentTitle(messages.length + " new messages with " + sender.toString())
 .setContentText(subject)
 .setSmallIcon(R.drawable.new_message)
 .setLargeIcon(aBitmap)
 // 2) set the style to MessagingStyle
 .setStyle(new NotificationCompat.MessagingStyle(resources.getString(R.string.reply_name))
 .addMessage(messages[0].getText(), messages[0].getTime(), messages[0].getSender())
 .addMessage(messages[1].getText(), messages[1].getTime(), messages[1].getSender()))


// 3) add an action with RemoteInput
.extend(new WearableExtender().addAction(action)).build();

Adding images to a MessagingStyle notification

You can add images to a notification message by setting the appropriate MIME type and placing the URI to the image in NotificationCompat.MessagingStyle.Message. setData() method.

Here is the code snippet to set data of type image in a notification:

NotificationCompat.MessagingStyle.Message message = new Message("sticker", 1, "Jeff")
                      .setData("image/png", stickerUri);

  NotificationCompat notification = new NotificationCompat.Builder()
             .setStyle(new NotificationComapt.MessagingStyle("Me")
             .addMessage(message)
             .build());

In the above code snippet the variable stickerUri is a Uri that points to a publicly-accessible location, as described here .

This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.