I want to send message from phone to wear (android watch). I dont want to send Notification. So I am using MessageApi to send the message. For some reason, my watch is not getting it. I used the same code in reverse order (wear to mobile), it works perfectly fine. From the phone end, its correctly recognizing the watch and display its name but in watch the message is not reached (onMessageReceived is not called).
Any help would be greatly appreciated.
The code in Mobile to send data:
private void resolveNode() {
Wearable.NodeApi.getConnectedNodes(mGoogleApiClient)
.setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
@Override
public void onResult(@NonNull NodeApi.GetConnectedNodesResult connectedNodes) {
for(Node connectedNode : connectedNodes.getNodes()) {
mNode = connectedNode;
Log.d(TAG,"Message Sender connected node"+mNode.getDisplayName());
sendMessage("Hello Hello");
}
}
});
}
private void sendMessage(final String message) {
if(mGoogleApiClient != null &&
mGoogleApiClient.isConnected() &&
mNode != null) {
Log.d(TAG,"Message is going to be sent to watch");
Wearable.MessageApi.sendMessage(mGoogleApiClient,
mNode.getId(),
"/mobile_data",
message.getBytes())
.setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
@Override
public void onResult(@NonNull MessageApi.SendMessageResult sendMessageResult) {
if(sendMessageResult.getStatus().isSuccess()) {
Log.e(TAG,"Message Succesfully sent to watch=>"+message);
} else {
Log.e(TAG,"Message FAILED TO BE SENT to watch=>"+message);
}
}
});
}
}
Code on the wearable side
public class MessageReceiver extends WearableListenerService {
private static final String TAG = "MessageReceiver";
@Override
public void onMessageReceived(MessageEvent messageEvent) {
super.onMessageReceived(messageEvent);
Log.d(TAG,"pathpathpathpath");
}
}
Registered my Message Receiver in AndroidManifest of wearable side
<service android:name=".MessageReceiver">
<intent-filter>
<action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
<data
android:host="*"
android:pathPrefix="/mobile_data"
android:scheme="mobile" />
</intent-filter>
</service>