Pitel
Pitel

Reputation: 5393

How to remove actions from wearable notification

I have a notification with couple of actions. I want to show it on wear, but without any action. How to do that?

builder.extend(new NotificationCompat.WearableExtender().addAction(null)); // Crashes
builder.extend(new NotificationCompat.WearableExtender().clearActions());  // Shows actions on Wear

Upvotes: 1

Views: 171

Answers (2)

Sterling
Sterling

Reputation: 6635

As @Teyam said, this isn't directly possible. One workaround would be:

  1. Set your notifications to not sync to the watch, using NotificationCompat.Builder.setLocalOnly().
  2. Create a WearableListenerService on the watch that generates a local notification there (with no actions) when a specific message is received.
  3. Send that message from your handheld app at the same time you generate the original notification.

I recognize that this is quite a bit more work than simply extending your original notification. It's up to you to decide whether not having actions on the wearable is worth the effort.

Upvotes: 0

Teyam
Teyam

Reputation: 8082

Been looking for any functions to remove actions in wearables but found SO post 1 and SO post 2 which basically state that it's not possible to remove actions. It is, however, mentioned in Specify Wearable-only Actions that

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 with NotificationCompat.Builder.addAction(). That is, only the actions added with WearableExtender.addAction() appear on the wearable and they do not appear on the handheld.

With that, you may opt to try setting an action which will appear only in wearable.

Hope that helps!

Upvotes: 1

Related Questions