[英]From Wear app check if Wear device is connected to Handheld device, 2021
From a Wear app I'm trying to constantly check if the Wear device is connected to the Handheld device.从 Wear 应用程序中,我试图不断检查 Wear 设备是否已连接到手持设备。 We can do that through
Wearable.getNodeClient(context).connectedNodes
.我们可以通过
Wearable.getNodeClient(context).connectedNodes
做到这一点。 Is there any way to add a listener to that data?有没有办法为该数据添加一个监听器? Also, is there any way to make sure any of these nodes is a Handheld device?
另外,有没有办法确保这些节点中的任何一个都是手持设备?
Using the CapabilityClient we can know if the app is installed by adding a capability to the wear.xml
file in the Handheld app.使用 CapabilityClient,我们可以通过在 Handheld 应用程序中的
wear.xml
文件中添加功能来了解应用程序是否已安装。 I am not looking to check that.我不打算检查。
I've also seen this question, but it doesn't answer mine.我也看过这个问题,但它没有回答我的问题。
Yes, you can add an ACTION_CAPABILITY_CHANGED
action to the manifest and then add a CapabilityClient listener.是的,您可以将
ACTION_CAPABILITY_CHANGED
操作添加到清单,然后添加CapabilityClient侦听器。 Within your OnCapabilityChangedListener
you can then check getNodes()
from the passed in CapabilityInfo
to obtain an updated list of available modes.在您的
OnCapabilityChangedListener
,您可以从传入的CapabilityInfo
检查 getNodes getNodes()
以获得可用模式的更新列表。 As for checking if it's a handheld or a watch, you should already have different capability strings for each, so you can simply filter the node set on the one you've set for the handheld.至于检查它是手持设备还是手表,您应该已经为每个设备设置了不同的功能字符串,因此您可以简单地过滤您为手持设备设置的节点集。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.