Skip to content

Most visited

Recently visited

navigation

Notification Styles

Android Wear supports notification styles to improve the user experience on a wearable device. The most common notification styles are:

The section below discusses how to add MESSAGING_STYLE and BIG_TEXT_STYLE into your notifications. To learn how to incorporate other notification styles, see the Wear Notifications sample.

Construct a MessagingStyle Notification

If you have a chat messaging app, your notifications should use NotificationCompat.MessagingStyle, which is new in Android 7.0. Wear 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

alt_text

Wear 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 .

Construct a BigTextStyle Notification

You can insert extended text content into your notification by using the BIG_TEXT_STYLE. On a handheld device, users can see the extended content by expanding the notification. On a wearable device, the expanded content is visible by default when you use the BigTextStyle.

alt_text

To add the extended content to your notification, call setStyle() on the NotificationCompat.Builder object, passing it an instance of either BigTextStyle or InboxStyle.

For example, the following code adds an instance of NotificationCompat.BigTextStyle to the event notification, in order to include the complete event description (which includes more text than can fit into the space provided for setContentText()).

// Specify the 'big view' content to display the long
// event description that may not fit the normal content text.
BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
bigStyle.bigText(eventDescription);

NotificationCompat.Builder notificationBuilder =
    new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_event)
        .setLargeIcon(BitmapFactory.decodeResource(
                getResources(), R.drawable.notif_background))
        .setContentTitle(eventTitle)
        .setContentText(eventLocation)
        .setContentIntent(viewPendingIntent)
        .addAction(R.drawable.ic_map,
                getString(R.string.map), mapPendingIntent)
        .setStyle(bigStyle);

Notice that you can add a large icon image to any notification using the setLargeIcon() method. However, these icons appear as large background images on a wearable and do not look good as they are scaled up to fit the wearable screen. To add a wearable-specific background image to a notification, see Add Wearable Specific-features For a Notification. For more information about designing notifications with large images, see the Design Principles of Android Wear.

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

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

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 short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)