I\'m writing a custom Android Wear application that\'s supposed to fire a one-off message to the connected host device (the phone). Digging through the API, I found the foll
Try add await() at the end of your sendMessage() method.
PendingResult messageResult = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(),
PATH, null).await();
The previous answer below is for sending message only when the Activity in Android device (mobile) is active.
Since you are trying to send message from Android Wear to Android device, the message listener should be added in the Activity in the Android device not in Android Wear, the following codes should be added into MainActivity in Android (mobile)
final GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.build();
googleApiClient.connect();
Wearable.MessageApi.addListener(googleApiClient, new MessageApi.MessageListener() {
@Override
public void onMessageReceived(MessageEvent messageEvent) {
Log.d(TAG, "Message received: " + messageEvent.getPath());
}
});
You can also try the simpler SendMessage() method
SendMessageResult result = Wearable.MessageApi.sendMessage(
mGoogleApiClient, node.getId(), "STRING TO BE SENT", null).await();
if (!result.getStatus().isSuccess()) {
Log.e(TAG, "ERROR: failed to send Message: " + result.getStatus());
}