taraloca
taraloca

Reputation: 9135

Message Not Received on Wearable

I have success with sending the message from the handheld, but the wearable is not receiving it:

I have my handheld send the message here:

 @Override
public void onConnected(Bundle arg0) {
    new SendToDataLayerThread(IS_PAID_VALUE, String.valueOf(Constants.PackageProperties.IS_PAID)).start();
}


private class SendToDataLayerThread extends Thread {
    String path;
    String message;

    // Constructor to send a message to the data layer
    SendToDataLayerThread(String p, String msg) {
        path = p;
        message = msg;
    }

    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(), path, message.getBytes()).await();
            if (result.getStatus().isSuccess()) {
                Log.v("myTag", "Message: {" + message + "} sent to: " + node.getDisplayName());
            }
            else {
                // Log an error
                Log.v("myTag", "ERROR: failed to send Message");
            }
        }
    }
}


 public class ListenerService extends WearableListenerService
        implements GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener {

    private static final String IS_PAID_VALUE = "/is-paid-value";

    private GoogleApiClient mGoogleApiClient;

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d(TAG, "onCreate");
        mBroadcastManager = LocalBroadcastManager.getInstance(getApplicationContext());

        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(Wearable.API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
        try {
            mGoogleApiClient.connect();
        } catch (Exception e) {
            Log.d(TAG, "onCreate: mGoogleApiClient.connect exception: " + e);
        }
    }

    @Override
    public void onMessageReceived(MessageEvent messageEvent) {
        Log.d("#####", "onMessageReceived: " + messageEvent);
        if (messageEvent.getPath().equals(IS_PAID_VALUE)) {
            String isPaid = new String(messageEvent.getData());
            Utilities.PackageProperties pp = new Utilities.PackageProperties();
            pp.setIsPaid(Boolean.parseBoolean(isPaid));
        }
    }

}

I never enter my onMessageReceived in my listener. I have it declared in my manifest to:

Upvotes: 2

Views: 697

Answers (1)

Marcelo Noguti
Marcelo Noguti

Reputation: 930

I had a very similar issue while developing for wearable. In my case, I could not receive any messages on mobile, even though they were sent successfully from the wearable.

After setting everything in both AndroidManifest, build.gradle and yada yada yada (same package name, applicationId, permissions and so on), I figured out that my app on mobile had several buildtypes and flavors. So..... I managed to solve the issue just configuring the flavors and buildtypes on wearable as well. After that, I could send and receive messages successfully between the two devices.

Hope it helps you. Cheers!

Upvotes: 2

Related Questions