Reputation: 691
So I have an application that can communicate just fine from phone to my LG G Watch. The issue is that I cannot send a message back. Here is my code for sending from the 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 the success message after sending. Here is the receiver service at 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 exact same code that I use in my watch application, which receives messages just fine. I'm sure that the service is properly started and declared, and that both applications have the same ID. Any suggestions?
Upvotes: 3
Views: 1080
Reputation: 691
I figured out that you have to have register the listener in onBind or OnCreate:
Wearable.MessageApi.addListener(googleApiClient, this);
Upvotes: 2