How to send notification from handheld to wear to open Activity on wear device
android-notifications, wear-os
Solution
The pattern to use for this is:
- Create a DataItem on the mobile. It will be synced to the connected wearable automatically.
- On the wearable, implement a `WearableListenerService` and listen for `onDataChanged` events.
- When you receive a `DataItem`, create a notification (with the data sent in the `DataItem`) and send it locally (i.e. on the wearable). Use `setContentIntent()` on the notification to specify a pending intent that will launch your wearable activity.
- Don't forget to also provide an intent that is fired when the user dismisses the notification on the wearable, so that the `DataItem` can be removed. Otherwise, you will not receive any update events.
I've created a sample project that shows all of this in action.
Check out this question if the `onDataChanged` method is not getting called.
Problem
I'm wondering if it is possible to send notification from handheld (android phone) to wear device to open Activity on wear device? What I want to do is as following. So far, I checked the following documents, but it's different from what I want to do. - Adding Wearable Features to Notifications - What is described here is sending notification from phone to wear, then open activity on the phone (I want to open activity on the wear) - Create Custom Notifications - What is described here is sending notification from wear to wear, then open activity on the wear (I want to send notification from phone to wear) Any ideas?