Notifications on Wear OS | Android Developers

Notifications on watches use the same APIs and have the lapp structure as notifications on phones .
Notifications can appear on a vigil in two ways :

  1. A mobile app creates a notification and the system
    automatically bridges that
    notification to the watch.
  2. A wearable app creates a notification.

For both scenarios, developers use the NotificationCompat.Builder class to create notifications. When you build notifications with the builder class, the system takes worry of displaying notifications by rights .
For example, when you issue a telling from your fluid app, each telling appears as a circuit board on the Notification Stream.

Use one of the NotificationCompat.Style subclasses for the best results .
To get started, see the detail sample on GitHub that demonstrates many mobile and wearable subclass styles .
Note: Notifications using RemoteViews are stripped of custom-made layouts and the clothing only displays the textbook and icons. however, you can create custom notifications that use custom-made card layouts that work well on the vigil .

Recommended notifications for wearables

We recommend using expandable notifications as the begin bespeak for all notifications, as they are a great way to engage wearable users. The crack up department of state is shown in the telling tray for a short, glanceable have. If the exploiter taps on it, the notification expands, revealing an immersive, scrollable have of extra contentedness and actions .
You can Create an expandable notification the like way you would on mobile with any of the NotificationCompat.Style subclasses. For model, a standard telling using NotificationCompat.MessagingStyle looks like this : expandable-notification
You can see the presentment has multiple Actions stacked at the penetrate of the expanded state.

For examples of NotificationCompat.BigPictureStyle, NotificationCompat.BigTextStyle, NotificationCompat.InboxStyle, and NotificationCompat.MessagingStyle, check out the Notification sample on GitHub. Tip: If your notifications include a “ Reply ” carry through ( such as for a messaging app ), you can enhance the behavior of the telling. For example, enable articulation input replies directly from the wearable or pre-defined text responses with setChoices(). For more information, read Add the reply button .

Avoiding duplicate Notifications

By default option, notifications are bridged from a company telephone app to any copulate watches. This is a great option if you do n’t have a wearable app installed .
however, if you build a standalone watch app and you have a companion earphone app, the apps will create double notifications .
wear OS provides a way to stop duplicate notifications with the Bridging APIs. For more information, read Bridging manner for notifications on Wear .

Add wearable specific-features to a notification

If you ever need to add wearable-specific features to a telling, such as hiding an app icon from the wearable presentment or letting users dictate a text response with voice remark, you can use the NotificationCompat.WearableExtender course to specify the options. To use this API, do the stick to :

  1. Create an instance of a

    WearableExtender, setting the wearable-specific options for the

  2. Create an instance of
    NotificationCompat.Builder, setting the desired properties for
    your notification as described earlier in this lesson.
  3. Call

    extend() on the notification and pass in the
    WearableExtender. This applies the wearable options to the notification.

  4. Call

    build() to build the notification.

Note: If you use the model ‘s NotificationManager, some features from NotificationCompat.WearableExtender do not work, so make sure to use NotificationCompat .
You can sync dismissals ( cancellations ) of notifications across the exploiter ‘s devices. To sync a dismissal setDismissalId() method. For each telling, pass a globally alone ID, as a string, when you call the setDismissalId() method acting. When the telling is dismissed, all other notifications with the same dismissal ID are dismissed on the watch ( east ) and on the companion phone. To retrieve a dismissal ID, use getDismissalId() .

Specify wearable-only actions

If you want different actions available on the lookout and the telephone, then use WearableExtender.addAction(). Once you add an action with this method, the clothing does not display any early actions added with NotificationCompat.Builder.addAction(). The actions added with WearableExtender.addAction() appear only on the wearable and they do not appear on the phone .

informant :
Category : Knowledge

Trả lời

Email của bạn sẽ không được hiển thị công khai.