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?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With