Wearable devices are very useful for apps as they allow users to read notifications without having to reach for a handheld.
To make use of notifications on a wearable, we need to have the Android Support Library v4 Component or the Xamarin.Android.Support.v4 NuGet installed on our handheld project.
We can make notifications automatically appear on a wearable if we manage our app's notifications using the NotificationCompat
type:
NotificationCompat
and NotificationManagerCompat
types:var notification = new NotificationCompat.Builder(this) .SetSmallIcon(Android.Resource.Drawable.StatSysDownload) .SetContentTitle("Wearable Notifications") .SetContentText("This is a notification from a device.") .SetContentIntent(pendingIntent) .Build(); var manager = NotificationManagerCompat.From(this); manager.Notify(NotificationId, notification);
var expandedStyle = new NotificationCompat.BigTextStyle(); expandedStyle.BigText("This is the extended text..."); var notification = new NotificationCompat.Builder(this) ... .SetStyle(expandedStyle) .Build();
SetAction()
method of the notification builder:var action = new NotificationCompat.Action.Builder( iconResource, "Open Maps", pendingIntent) .Build(); var notification = new NotificationCompat.Builder(this) ... .AddAction(action) .Build();
When an Android wearable device is connected to a handheld device, the handheld device automatically synchronizes notifications to this wearable. This allows users to read notifications without having to reach for the handheld. This hands-free ability is what makes this wearable device such a great convenience. Although not as powerful as a handheld, the wearable can often provide an overall improved user experience.
To provide notifications on the wearable, no extra code or configuration is required. All that needs to be done is to show the notification using the NotificationCompat
type. This type()
functions exactly similar to the Notification
type and supports all the Android versions from Android 2.0.
To show a notification, we will create it using the NotificationCompat.Builder
type. Once we have set all the properties, we will build it using the Build()
method. Then, to show the built notification, we will pass it to the Notify()
method on the NotificationManagerCompat
type.
In addition to displaying notifications, we can customize their appearance using various styles and actions. Each component of the notification is rendered differently and more appropriately on each type of device. Whether it is the handheld or wearable, the notification will be displayed in an easy-to-consume manner.