简体   繁体   English

WearableListenenerService onMessageReceived未调用

[英]WearableListenenerService onMessageReceived not called

I have made a simple Service that should receive messages from wear: 我做了一个简单的服务,应该从磨损中接收消息:

public class serviceforwatchlock extends WearableListenerService {

    @Override
    public void onMessageReceived(MessageEvent messageEvent) {
        super.onMessageReceived(messageEvent);

        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }
}

I checked if the onCreate method is called and it indeed is. 我检查了onCreate方法是否被调用,确实如此。

Also, here is my manifest: 另外,这是我的清单:

<service
            android:name=".serviceforwatchlock"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
                <data android:scheme="wear" android:host="*"
                    android:path="/start-activity" />
            </intent-filter>
        </service>

Now my wear code: 现在我的着装代码:

new Thread(new Runnable() {
            @Override
            public void run() {
                NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes( mApiClient).await();
                for(Node node : nodes.getNodes()) {
                    MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(
                            mApiClient, node.getId(), "/start_activity", "lockscreenGTP".getBytes() ).await();
                }
            }
        }).start();

The onMessageReceived method does not get called and I also dont get any error message. onMessageReceived方法不会被调用,我也不会收到任何错误消息。 What am I doing wrong? 我究竟做错了什么?

Based from this thread , one possible reason why you are encountering this is that your apps are signed with the different keys. 基于此线程 ,您遇到此问题的一个可能原因是您的应用使用了不同的密钥签名。 Package names of phone and wearable apps are the same and they also need to share the same signature. 手机和可穿戴式应用的程序包名称相同,并且它们还需要共享相同的签名。 Please make sure that you have both apps signed with the same key. 请确保两个应用程序都使用相同的密钥签名。 It is also suggested in this thread to check if applicationId was the same. 还建议在此线程中检查applicationId是否相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM