If I create an Notification I can add three Actions. Each action can also be invoked on a watch. Is it possible to make some of this actions not available on an Android Wear Watch?
Whenever you use addAction()
in NotificationCompat.WearableExtender
, you are not actually extending the actions (despite the name), but rather separating them into two lists, one for the phone, and one for the wearable.
NotificationCompat.Builder
are shown on the handheld.See Specifying Wearable-only Actions:
If you want the actions available on the wearable to be different from those on the handheld, then use
WearableExtender.addAction()
. Once you add an action with this method, the wearable does not display any other actions added withNotificationCompat.Builder.addAction()
. That is, only the actions added withWearableExtender.addAction()
appear on the wearable and they do not appear on the handheld.
Therefore, to have handheld-only actions, add them before creating the extender. And To have wearable-only actions, add them on the extender. If you use an extender and you want to have repeated actions in both devices, you must add them in both (though maybe there is an option to copy them?).
For example:
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("The title")
.setContentText("This is the text")
.setContentIntent(pendingIntent);
// Handheld-only actions.
notificationBuilder.addAction(drawable1, "In Both", pendingIntent);
notificationBuilder.addAction(drawable2, "Only in phone", pendingIntent);
// Wearable-only actions.
NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender();
wearableExtender.addAction(new NotificationCompat.Action.Builder(drawable2, "In Both", pendingIntent).build());
wearableExtender.addAction(new NotificationCompat.Action.Builder(drawable3, "Only in wearable", pendingIntent).build());
notificationBuilder.extend(wearableExtender);
// Build and show notification.
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(notificationId, notificationBuilder.build());
Also
WearableExtender
but don't add any actions into it, then the actions from the original notification are used.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With