我有一个Android穿戴应用程序,可以从一个配套的移动应用程序发送消息。当手机应用处于活动状态时,一切都运行良好,如果配套的手机应用不活跃,我需要能够从穿戴应用启动它……如何从wear应用程序启动移动应用程序?
你可以在你的移动应用程序中实现WearableListenerService,并从wear应用程序发送消息。这里有一个小要点来实现它。
//移动应用
public class ListenerServiceFromWear extends WearableListenerService {
private static final String HELLO_WORLD_WEAR_PATH = "/hello-world-wear";
@Override
public void onMessageReceived(MessageEvent messageEvent) {
/*
* Receive the message from wear
*/
if (messageEvent.getPath().equals(HELLO_WORLD_WEAR_PATH)) {
//For example you can start an Activity
Intent startIntent = new Intent(this, MyActivity.class);
startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startIntent);
}
}
}
你必须在你的Manifest中声明。
<service android:name=".ListenerServiceFromWear">
<intent-filter>
<action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
</intent-filter>
</service>