Notifications displayed on the wearable offer a hands-free experience for using apps; however, it is often desirable to provide the user with a wearable-specific experience.
Notifications from a handheld device can be easily displayed on wearables, but we can also provide special features for notifications that will only appear on a wearable:
NotificationCompat.WearableExtender
for wearable devices:var background = BitmapFactory.DecodeResource( Resources, Resource.Drawable.notificationBackground); var extender = new NotificationCompat.WearableExtender() .SetHintHideIcon(true) .SetBackground(background);
var icon = Android.Resource.Drawable.IcDialogDialer; var action = new NotificationCompat.Action( icon, "Make Call", pendingIntent); extender.AddAction(action);
Extend()
method:var notification = new NotificationCompat.Builder(this) ... .Extend(extender) .Build();
var manager = NotificationManagerCompat.From(this); manager.Notify(NotificationId, notification);
var extender = new NotificationCompat.WearableExtender(notification); var isIconHidden = extender.HintHideIcon;
Android automatically synchronizes notifications to the wearable, which is often enough. However, we can provide an improved experience for the wearable using the NotificationCompat.WearableExtender
type.
This type provides the means to override and customize the default notification functionality and appearance on the wearable device. Usually, the notification has an app icon in the corner of the notification, but we may wish to use a different look for our app.
If we create an instance of the WearableExtender
type, we can use it to modify the notification. We will use the SetHintHideIcon()
method to let the wearable know not to render the icon. Then, we set a background behind the content card using the SetBackground()
method. In addition to removing the icon, we can also change its position or use an icon that is different from the app icon.
The bitmap that we use with the SetBackground()
method should have a resolution of 400 × 400 for non-scrolling backgrounds and 640 × 400 for scrolling backgrounds. These images should be placed in the drawable-nodpi
resource folder. Other image resources for wearable notifications, such as icons, should be placed in the drawable-hdpi
resource folder.
Another method to override functionality is to provide a different set of actions for the wearable. When not providing actions via the extender, all the actions on the notification are available on the wearable. We may want to provide a more useful set of actions designed for a hands-free device. One such improvement would be to provide a reply by typing a response on the handheld; but on the wearable, we would provide a reply by a voice input.
To provide custom actions on a wearable, we can create the action using the NotificationCompat.Action
type. Then, instead of adding the action to the notification, we add the action to the wearable extender using the AddAction()
method.
Notifications using RemoteViews
are stripped of custom layouts, and the wearable will only display the text and icons. However, we can create the appearance custom notifications by creating an app that runs on the wearable device.
If the standard notification styles don't provide the required features or appearance, we can display a custom activity with a custom layout. Then, we can request for the wearable to issue a notification and set the activity as the display intent.
We can use normal mechanisms to display a notification from a wearable because the wearable is actually just a smaller Android device. Displaying a notification from the wearable is the same as displaying a notification on the handheld.