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?
Asked
Active
Viewed 3,862 times
1 Answers
9
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>

Gabriele Mariotti
- 320,139
- 94
- 887
- 841
-
1Can you add wear part to send Message? Would be great as I can't get it to work. – Michał Tajchert Aug 15 '14 at 22:07
-
1@GabrieleMariotti i install app on wearable, and launch it doesnot effect. Then i manually install mobile.app on mobile device, and launch on wearable device it does not effect too. What i do wrong? – Garf1eld Sep 16 '14 at 09:32
-
The com.google.android.gms.wearable.BIND_LISTENER action is deprecated – abbasalim Dec 14 '21 at 11:22
-
either deprecated here or doesnt work – Emil May 22 '22 at 19:41