问题描述
当通过本地节点打开一个通道
Wearable.NodeApi.getLocalNode(googleApiClient)
...的onChannelOpened监听器成功火灾。
然而,通过远程节点打开一个通道时,
Wearable.NodeApi.getConnectedNodes(googleApiClient)
...的onChannelOpened监听器的从不火灾,随后永远不能超过这个渠道共享文件。
我知道openChannel需要两个设备,但通道侦听器只发射打开它在本地...如何远程设备发送或接收的文件,以及如果它不知道它连接的设备上?下面是两个设备之间的击穿
耐磨:
- 保存本地文件 - 成功
- .openChannel当地(耐磨)节点 - 成功
- .sendFile频道 - 成功
举行处理:
- .openChannel远程(耐磨)节点 - 失败
- .receiveFile从通道 - 失败
- 显示文件 - 失败
Toubleshooting
下面有几件事情要检查:
-
您收到的消息事件或数据项更新?如果调用
Wearable.MessageApi.sendMessage
,你得到onMessageReceived
在其他设备上?如果没有,有可能是坏了怎么WearableListenerService
是建立在另一个节点上,或与您的应用程序被打包的方式(例如,您microapp和应用程序在不同的包,或与不同的密钥签名)。 -
您运行的是最新版本的?通道API最近添加,它可能是您的手表仍然没有收到更新来支持它。版本1.1.1.1889093应该罚款。
如何使用通道API
顺便说一句,这听起来像您可以简化渠道的使用。有没有需要打开同时向本地和远程节点的通道。你通常会使用API的方式是:
-
决定是否要开始从手表或手机的通道。在这种情况下,这听起来像你从手表开始吧。
-
在手表的应用程序,调用
Wearable.ChannelApi.openChannel
,在手机应用程序指向。该方法返回一个PendingResult< OpenChannelResult>
。当成功完成后,你会得到一个对象。这是通道的手表的一面,你可以用它来发送文件。 -
在手机应用程序,包括
WearableListenerService
,它应该得到一个onChannelOpened
事件。该方法将传递一个频道
对象,这是渠道的手机的一面。您可以拨打receiveFile
的对象。
因此,大家可以看到,你应该只有一个调用 openChannel
:到远程节点
When opening a channel via a local node:
Wearable.NodeApi.getLocalNode(googleApiClient)
... the onChannelOpened Listener successfully fires.
However, when opening a channel via a remote node:
Wearable.NodeApi.getConnectedNodes(googleApiClient)
... the onChannelOpened Listener never fires and subsequently can never share files over this channel.
I know openChannel is required for both devices, but the channel listeners are only firing on the device that opened it locally... How does the remote device send or receive files as well if it doesn't know it's connected? Here's breakdown between the two devices
Wearable :
- save local file - successful
- .openChannel with local (wearable) node - successful
- .sendFile to channel - successful
Handle Held :
- .openChannel with remote (wearable) node - fail
- .receiveFile from channel - fail
- display file - fail
Toubleshooting
Here are a few things to check:
Are you getting message events or data item updates? If you call
Wearable.MessageApi.sendMessage
, do you getonMessageReceived
on the other device? If not, there could be something wrong with howWearableListenerService
is set up on the other node, or with the way your app is packaged (e.g your microapp and app are in different packages, or are signed with different keys).Are you running the latest version of the Android Wear app? The Channel API was added recently, and it may be that your watch still hasn't received the update to support it. Version 1.1.1.1889093 should be fine.
How to use the Channel API
By the way, it sounds like you can simplify your use of channels. There's no need to open channels both to the local and to the remote node. The way you'd normally use the API is:
Decide whether you want to start the channel from the watch or from the phone. In this case, it sounds like you're starting it from the watch.
In the watch app, call
Wearable.ChannelApi.openChannel
, pointing at the phone app. This method returns aPendingResult<OpenChannelResult>
. When it completes successfully, you'll get aChannel
object. This is the watch's side of the channel, and you can use it to send a file.In the phone app, include a
WearableListenerService
, which should get anonChannelOpened
event. That method will be passed aChannel
object, which is the phone's side of the channel. You can callreceiveFile
on that object.
So as you can see, you should only have one call to openChannel
: to the remote node.
这篇关于Android Wear +耐磨ChannelApi openChannel与远程节点打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!