[英]WearableListenerService onMessageReceived not working
I am sending messages from my phone to the Wear.我正在从手机向 Wear 发送消息。 I want to be able to receive messages even when the wear activity is closed.
我希望即使在磨损活动关闭时也能收到消息。
I wrote a small service which launches my main Activity (UI) if it receives a message.我写了一个小服务,如果它收到一条消息,它会启动我的主要活动(UI)。 However, the onMessageReceived function never gets called in the WearableListenerService.
但是,在 WearableListenerService 中永远不会调用 onMessageReceived 函数。 I also tried the sample code at this tutorial , but it doesn't seem to work for me.
我还尝试了本教程中的示例代码,但它似乎对我不起作用。
What I have tried so far:到目前为止我尝试过的:
Here is the code:这是代码:
Wear Manifest:磨损清单:
<service android:name=".MessageService">
<intent-filter>
<action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
<action android:name="com.google.android.gms.wearable.CAPABILITY_CHANGED" />
<action android:name="com.google.android.gms.wearable.CHANNEL_EVENT" />
<action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
<data android:scheme="wear" android:host="*" android:pathPrefix="/prefix" />
</intent-filter>
</service>
MessageService:消息服务:
public class MessageService extends WearableListenerService {
public Handler h;
@Override
public void onCreate() {
Log.i("service", "im here");
}
@Override
public void onMessageReceived(MessageEvent messageEvent) {
Log.i("onMessageReceived","im here!");
Intent intent = new Intent( this, MainActivity.class );
intent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
startActivity( intent );
}
The code the Main Activity in Wear and the main activity on mobile is from this example. Wear 中的 Main Activity 和移动设备上的 main Activity 的代码来自此示例。 .
.
The communication within the activity works, the service is not working.活动内的通信有效,服务无效。 Help?
帮助?
The message path in the mobile app has to match that in the intent filter of the service.移动应用程序中的消息路径必须与服务的意图过滤器中的路径相匹配。 You have this as '/prefix' in the intent filter but is 'message1' or 'message2' in the mobile app.
您在意图过滤器中将此作为“/前缀”,但在移动应用程序中为“message1”或“message2”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.