diff --git a/docs/html/wear/preview/features/notifications.jd b/docs/html/wear/preview/features/notifications.jd index dcc09709deb3f..b546978a8b9cc 100644 --- a/docs/html/wear/preview/features/notifications.jd +++ b/docs/html/wear/preview/features/notifications.jd @@ -1,6 +1,5 @@ page.title=Notification Changes in Android Wear 2.0 -meta.tags="wear", "wear-preview", "notifications" -page.tags="wear" +meta.tags="wear", "wear-preview", "notifications" page.tags="wear" page.image=/wear/preview/images/expanded_diagram.png @@ -12,6 +11,7 @@ page.image=/wear/preview/images/expanded_diagram.png

This document includes

  1. Visual Updates
  2. +
  3. Inline Action
  4. Expanded Notifications
  5. MessagingStyle
@@ -67,7 +67,8 @@ material design visual changes. We recommended that you don't set color for bridged notifications. When Wear apps post local notifications, you can work around this by checking - the API level of the device they're running on and using an appropriate color + the API level of the device + they're running on and using an appropriate color for Wear 1.x and a different color for Wear 2.0. @@ -77,6 +78,85 @@ material design visual changes. you must update the text of your notification. + +

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 {@code 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 + {@code 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. + +
  3. + Use the {@code addRemoteInput()} + method to attach the {@code 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);
    +
    +
  4. + +
  5. + Add a hint to display the reply action inline, and use the + {@code 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());
    +
    +
  6. +
+

Expanded Notifications

Android Wear 2.0 introduces expanded notifications, which provide substantial additional content and actions for each notification. @@ -152,51 +232,52 @@ action in the notification unless a different action is specified using

MessagingStyle

-

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

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

-

Note: {@code MessagingStyle} +

Note: {@code MessagingStyle} expanded notifications require that you have at least version 1.5.0.2861804 of the Android Wear app - on your paired Android phone. That version will be available within the next - few weeks in the Play Store. + on your paired Android phone.

Smart Reply

-

Wear 2.0 also introduces Smart Reply -for {@code MessagingStyle} notifications. +

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

-

By enabling Smart Reply for your MessagingStyle notifications, - you provide users with a fast (single tap), discreet (no speaking aloud), and - reliable way to respond to chat messages. -

- -

Responses generated by Smart Reply are shown in addition to those set using the + {@code RemoteInput} + using the {@code 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 {@code Notification.MessagingStyle}. +
  2. Use {@code NotificationCompat.MessagingStyle}.
  3. -
  4. Call the method {@code setAllowGeneratedReplies()} for the notification action. - For more information, see the downloadable - API reference. +
  5. Call the method {@code setAllowGeneratedReplies(true)} + for the notification action.
  6. Ensure that the notification action has a {@code RemoteInput} @@ -236,3 +317,29 @@ Notification noti = new NotificationCompat.Builder() // 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 {@code NotificationCompat.MessagingStyle.Message.} + {@code 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 + . +

    \ No newline at end of file diff --git a/docs/html/wear/preview/images/inline_action.png b/docs/html/wear/preview/images/inline_action.png new file mode 100644 index 0000000000000..7ecaafeb25441 Binary files /dev/null and b/docs/html/wear/preview/images/inline_action.png differ