如何检测,如果Android设备配对与Android磨损腕表磨损、腕表、设备、Android

2023-09-12 07:41:58 作者:我就拽了你能怎么滴

我创建一个Android应用程序磨损延伸推送通知。我的应用程序从服务器下载大约10时,图像推送通知进来,对手表显示这些额外的图像。这些图像是具体到Android磨损应用程序和手持设备上不显示。

I am creating an android wear app that extends push notifications. My app downloads approximately 10 images from a server when a push notification comes in and displays these additional images on the watch. These images are specific to the android wear app and are not shown on the handheld device.

我如何判断手持设备搭配一个Android设备的磨损,这样我可以决定是否有必要下载所需磨损应用程序中的其他图像?

How do I tell if the handheld device is paired with an android wear device so that I can determine if it is necessary to download the additional images required for the wear app?

谢谢!

推荐答案

您需要使用 NodeApi ,特别是 NodeApi.getConnectedNodes()

You need to use the NodeApi, in particular NodeApi.getConnectedNodes().

例如(从后台线程 - 以其它方式使用 setResultCallback(),而不是等待()):

For example (from a background thread -- otherwise use setResultCallback() and not await()):

List<Node> connectedNodes =
    Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await().getNodes();

如果返回的节点的列表包含至少一个元素,则有一连接Android Wear装置,否则有不

If the list of nodes returned contains at least one element, then there is a connected Android Wear device, otherwise there isn't.

更新:随着的谷歌播放服务7.3 ,可同时连接多台Android Wear设备的支持已被添加。您可以使用 CapabilityApi 请求节点具有特定的功能。

Update: With the release of Google Play Services 7.3, support for multiple Android Wear devices connected simultaneously has been added. You can use the CapabilityApi to request nodes with specific capabilities.