如何从磨损应用程序启动移动应用程序?

Cri*_*ris 8 android wear-os

我有一个Android Wear应用程序,可以从配套的移动应用程序发送消息.当移动应用程序处于活动状态时,所有运行正常,如果配套移动应用程序未激活我需要能够从磨损应用程序启动它...如何从磨损应用程序启动移动应用程序?

Gab*_*tti 7

您可以在移动应用程序中实现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);
        }

    }     
}
Run Code Online (Sandbox Code Playgroud)

你必须在你的清单中声明它.

  <service android:name=".ListenerServiceFromWear">
        <intent-filter>
            <action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
        </intent-filter>
    </service>
Run Code Online (Sandbox Code Playgroud)

  • @ Garf1eld https://gist.github.com/gabrielemariotti/117b05aad4db251f7534 (2认同)