I'm building a Wear app that will communicate with a WearableListenerService on the handheld. However, i want to make sure that service is up and running when the app starts on the watch.
My initial thought was either send an intent or a broadcast message to get the service started. However, i've been unable to figure out how to get the watch to send that to the paired handheld instead.
On the watch side:
Intent intent = new Intent();
intent.setAction("my.wearable.CONNECT");
sendBroadcast(intent);
On the handheld side:
public class WearableBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent startServiceIntent = new Intent(context, WearableService.class);
context.startService(startServiceIntent);
}
}
<receiver android:name=".service.wearable.WearableBroadcastReceiver" >
<intent-filter>
<action android:name="my.wearable.CONNECT" />
</intent-filter>
</receiver>
There are couple of things that need to clear
The communication interfaces between an Android Wear Device and an Android Device are the following
Use NodeApi to get the connected Node ID.
You cannot send a intent from wear side and expect to receive it on the phone side.
On the phone side, if you are extending WearableListenerService
then this service is self managed by Android OS. Meaning, if the service were to receive a message or data from wear, Android would automatically create the service, service your request and destroy the service if required. You do not have to do any special thing here.
The intent defined in the manifest (copy pasted above) is good enough for Android OS to do the above stated management of the 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