如何从手持设备发送通知以穿戴打开设备上的活动 [英] How to send notification from handheld to wear to open Activity on wear device

查看:60
本文介绍了如何从手持设备发送通知以穿戴打开设备上的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以从手持设备(Android手机)向穿戴设备发送通知以打开穿戴设备上的活动?我想做的如下.

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.

  • 向通知中添加可穿戴功能
    • 这里描述的是从手机发送通知,然后在手机上打开活动(我想在衣服上打开活动)
    • 这里描述的是从穿戴发送通知,然后在穿戴上打开活动(我想从穿戴发送通知)

    有什么想法吗?

    推荐答案

    用于此的模式是:

    1. 在移动设备上创建 DataItem .它将自动同步到所连接的可穿戴设备.
    2. 在可穿戴设备上,实现WearableListenerService并监听onDataChanged事件.
    3. 当您收到DataItem时,创建一条通知(数据在DataItem中发送)并本地发送(即在可穿戴设备上).在通知上使用setContentIntent()指定将启动可穿戴活动的待定意图.
    4. 别忘了提供一个意图,当用户关闭可穿戴设备上的通知时会触发该意图,因此可以删除DataItem.否则,您将不会收到任何更新事件.
    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.

    如果未调用onDataChanged方法,请查看此问题.

    Check out this question if the onDataChanged method is not getting called.

    这篇关于如何从手持设备发送通知以穿戴打开设备上的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆