5

How can I supress the "open on phone" action on a wearable? I added a more helpful custom action which is now a dublicate action. Any idea how I can remove it?

Here is a snip it how I build the Notification:

NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
    .setContentTitle("Title")
    .setContentText("Message")
    .setSmallIcon(R.drawable.icon)
    .setContentIntent(openIntent);
NotificationCompat.WearableExtender extender =
                   new NotificationCompat.WearableExtender();
extender.addAction(new NotificationCompat.Action.Builder(icon, "do something",
                   openIntent).build());
builder.extend(extender);

I know that I can create a second notification which is only visible on the wearable but that cannot be wanted by android that I need to create a seperate notification isn't it?

rekire
  • 47,260
  • 30
  • 167
  • 264
  • Sorry, but I don't understand the last sentence (what you're trying to say there): "[...]but that cannot be wanted by android that I need to create a seperate notification isn't it?" – Maciej Ciemięga Sep 16 '14 at 14:06
  • I mean it is possible to create seperat notifications, for the device and the wearable, but I think that is too much overhead. – rekire Sep 16 '14 at 14:09
  • Have you looked at the "Notification" sample provided for Android Wear by the SDK Manager? See if you can generate the type of notification you want from that sample, it has a UI which can provide pretty much every combination possible. – Wayne Piekarski Sep 16 '14 at 20:43
  • @WaynePiekarski I expect you are talking about `sdk\samples\android-20\wearable\Notifications\Wearable\src\main\java\com\example\android\support\wearable\notifications` right? – rekire Sep 17 '14 at 06:02
  • @rekire: Almost correct - you will need to import sdk/samples/android-20/wearable/Notifications into Android Studio, and build the phone version of the sample and run that. The phone version is in the Application directory, and the relevant code is in sdk/samples/android-20/wearable/Notifications/Application/src/main/java/com/example/android/support/wearable/notifications – Wayne Piekarski Sep 17 '14 at 16:12

2 Answers2

2

According to the documentation the "Open on phone" action is added automatically when you have any PendingIntent set in setContentIntent(PendingIntent intent) method.

When this notification appears on a handheld device, the user can invoke the PendingIntent specified by the setContentIntent() method by touching the notification. When this notification appears on an Android wearable, the user can swipe the notification to the left to reveal the Open action, which invokes the intent on the handheld device.


I don't think you can "disable" this action (apart from just not specifying the contentIntent, but I guess that this is not a solution for you).

I'm not familiar with your exact situation, but mostly people set contentIntent on a notification to launch some Activity that shows details or to allow user to do some more things (like input, configuration etc). In that case I don't see a need to try to disable this extra action even if you are serving some kind of "lightweight" solution right on your Android Wear device.

But if you really want to get rid of this "Open on phone" action (while still having the contentIntent set on phone) you will need to have separate notification published from the Android Wear device.

You will need to use DataApi to sync your notification state. See more details about DataApi in the documentation:
https://developer.android.com/training/wearables/data-layer/index.html https://developer.android.com/training/wearables/data-layer/data-items.html

Also you can check an example of usage of DataApi in one of my answers.

Community
  • 1
  • 1
Maciej Ciemięga
  • 10,125
  • 1
  • 41
  • 48
  • I'm more or less familiar with the DataAPI, when I know that I should show my notification how can I achieve that I get the same style etc. Can I use the notification API on the wearable too? – rekire Sep 16 '14 at 14:29
  • On your phone you will have to add `setLocalOnly(boolean)` on your phone notification to prevent it from being shown on Android Wear device. Then you will have to "replicate" this notification on the Android Wear device. To achieve the "same look" you can share the code that is generating the notification (of course with some modifications according to your purposes, like not specifying `setContentIntent` for wearable version). Then you will end up with basically the same notification but without the "Open on phone" action. – Maciej Ciemięga Sep 16 '14 at 14:36
  • I know the setLocalOnly() method but I don't found the antipatter yet, I also stack the notifications in the wearable notification. So the group hack is also no option. – rekire Sep 16 '14 at 14:40
  • So the only solution is like I said - you need to implement the Wearable app and post the notification from there + syncing these notifications with phone using `DataApi`. AFAIK there is no other solution to achieve it with your desired functionality. – Maciej Ciemięga Sep 16 '14 at 14:42
  • I'll try tomorrow to create a notification on the wearable itself maybe that works too. – rekire Sep 16 '14 at 14:44
  • It seems to work with some restrictions. I can create notifications on the wearable with [some smaller](http://stackoverflow.com/q/25885233/995926) and [bigger restrictions](http://stackoverflow.com/q/25885364/995926). – rekire Sep 17 '14 at 08:14
1

This answer seems to be out of date for Wear OS 2.x. I'm trying to update this answer as soon I can.

I ended in creating multiple notifications. Here is an example:

// for the wearable
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
    .setContentTitle("Title")
    .setContentText("Message")
    .setSmallIcon(R.drawable.icon)
    .setContentIntent(openIntent)
    .setGroup("MyGroup")
    .setDeleteIntent(magic());
    // since I don't set setGroupSummary(true) this
    // notification will not been display on a mobile
NotificationCompat.WearableExtender extender =
                   new NotificationCompat.WearableExtender();
extender.addAction(new NotificationCompat.Action.Builder(icon, "do something",
                   openIntent).build());
builder.extend(extender);
// fire it

// for the mobile
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
    .setContentTitle("Title")
    .setContentText("Message")
    .setSmallIcon(R.drawable.icon)
    .setContentIntent(openIntent)
    .setLocalOnly(true) // the magic to hide it on the wearable
    .setDeleteIntent(magic());
// fire it

With magic() I create a PendingIntent which invokes a BroadcastReciever which hides the other notifications to keep them in sync.

rekire
  • 47,260
  • 30
  • 167
  • 264
  • This is the approach that I have described here: http://stackoverflow.com/a/24916387/3827276 but since you want to have some actions in this notification (that is grouped) this is not the best approach. Issue with this solution is that you will end up with group with only one notification - it will be displayed just like a single notification, but you won't be allowed to swipe to the action pages. You will need to click on it (to enter the only one notification in this group (which should be fixed on Android Wear platform IMO). Maybe this is fixed in new AW system update, can you confirm that? – Maciej Ciemięga Sep 18 '14 at 18:59
  • Could you please confirm if this issue (from my comment above) occurs on newer Android Wear system update or not? This is very important to me, thanks! – Maciej Ciemięga Sep 24 '14 at 13:14
  • Sorry I missed your comment, you are right if this is the only notification another tap is requiered. But I think too that this behavior is a bug of AW. – rekire Sep 24 '14 at 13:36
  • Yeah, it is really a terrible user experience - user sees one notification which looks exactly like a standard notification - but behaves differently and needs a tap to show actions:\ I really hope they will fix that behavior - then this solution with single notification group will be great for providing alternative notification on Wear without implementing it on wearable side. – Maciej Ciemięga Sep 24 '14 at 13:46