How to send notification from handheld to wear to open Activity on wear device

放肆的年华 提交于 2019-11-29 19:44:35
Peter Friese

The pattern to use for this is:

  1. Create a DataItem on the mobile. It will be synced to the connected wearable automatically.
  2. On the wearable, implement a WearableListenerService and listen for onDataChanged events.
  3. 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.
  4. 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.

I think in most cases it would be better to include your app activity inside the notification. For example, instead of the "Open" button in your notification, you could use setDisplayIntent(notificationPendingIntent) to display an activity as part of the notification as described here: http://developer.android.com/training/wearables/apps/layouts.html

This gives you a best of both worlds situation between having an app and a notification.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!