wear-osandroid-wear-notification

How to specify no actions for android wear notifications?


I have a couple actions for my notifications, however I don't want any of them available on android wear. I know I can specify a list of custom actions for android wear, but how do I specify none? (I've tried addActions with an empty list, but no luck - then it just shows all the actions)


Solution

  • I don't think this is possible in standard way. If you specify at least 1 action in WearableExtender then normal actions will be replaced with wearable actions, but as you've said - you want to have 0 wearable actions.

    For me you have 2 solutions:

    1. Go with the API design post alternative versions of actions with your WearableExtender. If really any of phone actions cannot be used on watch maybe you can think of anything else that would be useful. It won't hurt user to be able to perform any action from watch. Of course if that makes sense in your case.

    2. If you want to "hack" it a bit you can "clone" the notification and make them a part of the same group. If you would set one as a "group summary" that one will show up only on phone and other will be visible only on wearable. That way you have ability to setup completely independent set of actions.

    Sample code:

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    // configure your builder without actions
    builder.setGroup(GROUP_TAG);
    builder.setGroupSummary(false);
    notificationManager.notify(WEARABLE_NOTIFICATION_ID, builder.build());
    
    // add some actions that will be visible only on phone
    builder.addAction(...)
    builder.addAction(...)
    builder.setGroupSummary(true);
    notificationManager.notify(PHONE_NOTIFICATION_ID, builder.build());