MessageAPI android Wear, can send messages to socks, but wearable can not send message back

So, I have an app that can communicate perfectly with the phone in the LG G Watch. The problem is, I cannot send the message back. Here is my code for sending from wearable, which always indicates that the message has been sent:

public void oops(View view){
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {

            NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
            for (Node node : nodes.getNodes()) {
                MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), "/start/MainActivity", "Hello".getBytes()).await();
                if (!result.getStatus().isSuccess()) {
                    Log.e("INFO", "ERROR");
                } else {
                    Log.i("INFO", "Success sent to: " + node.getDisplayName());
                }

            }
        }
    });
    thread.start();
}

      

I always get a success message after submitting. Here is the receiver service on the other end:

    public class Reciever extends Service implements MessageApi.MessageListener {
    public Reciever() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public void onMessageReceived(MessageEvent messageEvent) {
        Log.i("INFO", "We got it!");
    }
}

      

This is the same code I am using in my watch viewer app that receives messages just fine. I am confident that the service is started and declared correctly, and that both applications have the same ID. Any suggestions?

+3


source to share


1 answer


I figured out that you need to register the listener with onBind or OnCreate:



Wearable.MessageApi.addListener(googleApiClient, this);

      

+2


source







All Articles