Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Wear + Wearable ChannelApi openChannel not opening with remote node?

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 :

  1. save local file - successful
  2. .openChannel with local (wearable) node - successful
  3. .sendFile to channel - successful

Handle Held :

  1. .openChannel with remote (wearable) node - fail
  2. .receiveFile from channel - fail
  3. display file - fail
like image 583
worked Avatar asked Feb 11 '23 06:02

worked


1 Answers

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 get onMessageReceived on the other device? If not, there could be something wrong with how WearableListenerService 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:

  1. 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.

  2. In the watch app, call Wearable.ChannelApi.openChannel, pointing at the phone app. This method returns a PendingResult<OpenChannelResult>. When it completes successfully, you'll get a Channel object. This is the watch's side of the channel, and you can use it to send a file.

  3. In the phone app, include a WearableListenerService, which should get an onChannelOpened event. That method will be passed a Channel object, which is the phone's side of the channel. You can call receiveFile on that object.

So as you can see, you should only have one call to openChannel: to the remote node.

like image 88
Nimrod Gileadi Avatar answered Feb 15 '23 11:02

Nimrod Gileadi