Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wearable MessageAPI onMessageReceived never hit, different devices id's

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.

like image 514
Kris B Avatar asked Aug 09 '17 14:08

Kris B


1 Answers

First of all, do not use deprecated methods like onPeerConnected. Always use CapabilityApi methods instead. This is improtaint!

I've got a question. Which kind of Android Wear APK (on handheld) file are you using? Don't you know that modern versions of Android Wear APK are not useful? They doesn't work properly.

If you are using old version of API you have to understand that modern APIs such as CapabilityApi doesn't work.

Nowadays, this is not possible to make a stable connection between emulated Wearable and emulated Handheld. One of them have to be a real device.

The only solution that I can suggest is to test your application of real wearable and handheld devices.

Always use up-to-date GoogleServices library to test, use real devices, use not deprecated APIs.

Before publishing decrease GoogleServices library version in order to make your app workable for not updated devices.

In my practice, emulators work very strange.

like image 70
Vyacheslav Avatar answered Oct 19 '22 05:10

Vyacheslav