Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OnMessageReceived not called in WearableListenerService

Tags:

android

I am working on android wear app using Eclipse IDE.I am using same package names for wear app and mobile app and i am packing wearable app manually according to google documentation.Everything is working fine.it is installed on Android wear emulator using usb debugging with phone.

My problem is when i am sending a message to wearable using following code

List<Node> nodeList=getNodes();
for(Node node : nodeList) {
    Log.v(" ", "telling " + node.getId() );

    PendingResult<MessageApi.SendMessageResult> result = Wearable.MessageApi.sendMessage(
        mGoogleApiClient,
        node.getId(),
        START_ACTIVITY_PATH,
        null
    );

    result.setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
        @Override
        public void onResult(MessageApi.SendMessageResult sendMessageResult) {
            Log.v(" ", "Phone: " + sendMessageResult.getStatus().getStatusMessage());
        }
    });
}

the OnPeerConnected method is running when devices are peered but OnMessageReceived never called in WearableListenerService.This is my WearableListenerService code:

public class DataLayerListenerService extends WearableListenerService {

    private static final String TAG = "DataLayerSample";
    private static final String START_ACTIVITY_PATH = "/start/MainActivity";
    private static final String DATA_ITEM_RECEIVED_PATH = "/data-item-received";
    private static final String LOG_TAG = "log";
    @Override
    public void onPeerConnected(Node peer) {
        super.onPeerConnected(peer);

        String id = peer.getId();
        String name = peer.getDisplayName();

        Log.d(LOG_TAG, "Connected peer name & ID: " + name + "|" + id);
    }
    @Override
    public void onDataChanged(DataEventBuffer dataEvents) {
        System.out.println("Recevive message3");
    }

    @Override
    public void onMessageReceived(MessageEvent messageEvent) {
        System.out.println("service watch message1");
        if (messageEvent.getPath().equals(START_ACTIVITY_PATH)) {
            System.out.println("service watch message2");
            Intent startIntent = new Intent(this, MainActivity.class);
            startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(startIntent);
        }
    }
}

Also a warning message in Logcat always appears :

app does not match record's app key: AppKey[com.myapp,c3f31717fa35401056c20a2798907f1232efa75e] != AppKey[com.myapp,f36e726eefc7e528db26a1c25f6fbf2f93dacd70]

If app key for both apps should be same then how can i create same app key for both the apps.

Any help is highly appreciated, Thanks.

like image 839
Lakhan Sharma Avatar asked Jul 25 '14 14:07

Lakhan Sharma


1 Answers

The error message you have:

app does not match record's app key: AppKey[com.myapp,c3f31717fa35401056c20a2798907f1232efa75e] != AppKey[com.myapp,f36e726eefc7e528db26a1c25f6fbf2f93dacd70]

Indicated that your apps are signed with the different keys.
Package names of phone and wearable apps are the same - that is good, but they also need to share the same signature. This is the reason why messages cannot be delivered - wearable apps are recognized as "part of the same app" based on the package name and signature.

Please make sure that you have both apps signed with the same key. If you are testing the autoinstallation feature please make sure to uninstall the debug version of wearable app from watch emulator.

like image 145
Maciej Ciemięga Avatar answered Nov 15 '22 16:11

Maciej Ciemięga