Trying to send a message from an emulated mobile device to an emulated wear device. I'm able to pair the wear device through the Android Wear app and verify that onPeerConnected
of the wear device is hit (onMessageReceived
isn't).
Using two code versions to return node.getId()
results in two different id's of the wear device.
Running this:
new Thread(new Runnable() {
@Override
public void run() {
NodeApi.GetLocalNodeResult nodes = Wearable.NodeApi.getLocalNode(mGoogleApiClient).await();
Node node = nodes.getNode();
MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), "Hello Watch 1", null).await();
if (!result.getStatus().isSuccess()) {
Log.e(getPackageName(), "error");
} else {
Log.i(getPackageName(), "success!!!! sent to: " + node.getId());
}
}
}).start
returns: 08-09 10:24:33.106 17914-18007/com.wear.myapp I/com.wear.myapp: success!!!! sent to: 223faf0e
Running this:
new Thread(new Runnable() {
@Override
public void run() {
NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();
for (Node node : nodes.getNodes()) {
MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), "Hello Watch 2", null).await();
if (!result.getStatus().isSuccess()) {
Log.e(getPackageName(), "error");
} else {
Log.i(getPackageName(), "success!!!! sent to: " + node.getId());
}
}
}
}).start();
Returns: 08-09 10:24:33.108 17914-18006/com.wear.myapp I/com.wear.streamer: success!!!! sent to: 3a000c12
Even stranger hardcoding in a fake Node ID for the wear device still returns a success message in the logs. Feel like I'm getting a false positive result.
WearableListenerService:
@Override
public void onMessageReceived(MessageEvent messageEvent) {
Log.i(getPackageName(), "Message received");
}
@Override
public void onPeerConnected(Node peer) {
Log.i(getPackageName(), "Peer connected");
}
I've read through every SO questions similar to this but haven't seen anyone mention different device id's. I've triple-checked that the applicationIds and dependencies are identical between mobile and wear.
UPDATE:
If unpair the Wear emulator and run Wearable.NodeApi.getLocalNode
I still get a nodeId returned, while Wearable.NodeApi.getConnectedNodes
does not, which leads me to believe getConnectedNodes
is what I should be using.
Also, shutting down the Wear emulator still returns a connected node id for getLocalNode
which leads me to believe it's returning something other then the watch.
onPeerConnected
was deprecated. Usually Android Studio will display a message if an api is deprecated but it's not foronPeerConnected
. Unfortunately, the devices I own do not have the APIs I need yet, so I'm forced to use the emulator. I'll look into theCapabilityAPI
. Thanks – Heed