androidwear-osandroid-wear-notification

How to open a Wear Activity from a Notification created by Phone


Currently when I receive a Push notification I create a notification. This notification is shown on phone and Android wear. The notification has one action: Open on phone.

How can I create a second action to open an Activity on the wearable?

I tried using NotificationCompat.WearableExtender and adding an action. But how can I use the Wear Activity in the PendingIntent? Because the Wear Activity is in another module I don't have access to it in my Phone module, where the Push notification is received.


Solution

  • You cannot open an activity on a wear device using a notification that was created on a phone; all the actions/intents refer to the originator of the notification (i.e. phone if phone created the notification). You need to do a bit of work to create the effect that you want; basically need to have a wear app as well and instead of creating a notification on the phone for wear, send a message, from your phone to the wear device and have teh wear app on your wear device capture that message and create a notification on the wear device. Then that notification can open an activity (since it was originated on your wear device). As a sample app, take a look at the SynchronizedNotifications that does this.