我做了一个简单的服务,应该接收来自穿着的信息:
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();
}
}
我检查了onCreate方法是否被调用,确实是。
此外,这是我的清单:
<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>
现在我的磨损代码:
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();
onMessageReceived方法没有被调用,我也没有收到任何错误消息。我做错了什么?