Cris
Cris

Reputation: 12194

How to start mobile app from wear app?

I have an Android wear app that send messages from and to a companion mobile app. When the mobile app is active all runs fine, if the companion mobile app is not active i need to be Able to launch it from wear app... How do i launch the mobile app from the wear app?

Upvotes: 9

Views: 4190

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363825

You can implement a WearableListenerService in your mobile app and send a Message from wear app. Here a little gist to achieve it.

//Mobile app

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);
        }

    }     
}

You have to declare it in your Manifest.

  <service android:name=".ListenerServiceFromWear">
        <intent-filter>
            <action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
        </intent-filter>
    </service>

Upvotes: 10

Related Questions