Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 937
Cris Avatar asked Aug 03 '14 15:08

Cris


1 Answers

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>
like image 120
Gabriele Mariotti Avatar answered Sep 26 '22 03:09

Gabriele Mariotti