I have an application where the smartwatch collects some data and send to the phone. I'm using WearableListenerService and GoogleAPIClinet. During the data collection, I want to know when the connection fails. The two functions onConnectionSuspended() and onConnectionFaile() never called even if I turn the bluetooth off. Is there any way to check when the connection drops?
The two functions you mention (onConnectionFailed
and onConnectionSuspended
) refer to the connection with the Google API client, not with other devices. They'll very rarely get called under normal circumstances.
To detect a change in device connectivity, use the Capability API. Specifically, you want onCapabilityChanged
- which, despite the name, gets called when the list of connected, capable nodes has changed, not when capabilities themselves have changed. Documentation is here: https://developer.android.com/training/wearables/apps/standalone-apps.html#detecting-your-app