简体   繁体   中英

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.

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 (ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM