0

Please say how we can show notification on android as soon as the wear is paired to device, like the weather notification from google.

Thanks

Mobile Dev
  • 70
  • 5

1 Answers1

0

You can implement a custom capability on the phone. Your wearable would listen to this capability with a WearableListenerService: override onCapabilityChanged. When the phone connects to the wearable, the capabilities provided by reachable nodes (from the watch) are updated and onCapabilityChanged is called.

See the documentation Advertise and Retrieve capability.

Advertise : (res/values/wear.xml) (mobile resources)

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="android_wear_capabilities">
        <item>my_phone_capability</item>
    </string-array>
</resources>

Listen to changes on reachable capabilities : (WearableListenerService, service declared in the manifest with intent action BIND_LISTENER)

@Override
public void onCapabilityChanged(CapabilityInfo capabilityInfo) {
    String mPhoneNodeId = pickBestNodeId(capabilityInfo.getNodes());
    // you can check if it's the capability you want (my_phone_capability)
    if (mPhoneNodeId == null) {
        // phone is disconnected
    } else {
        // phone is connected, send notif
    }
}
Kapouter
  • 147
  • 10