How to detect if android device is paired with android wear watch
You need to use the NodeApi
, in particular NodeApi.getConnectedNodes()
.
For example (from a background thread -- otherwise use setResultCallback()
and not await()
):
List<Node> connectedNodes =
Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await().getNodes();
If the list of nodes returned contains at least one element, then there is a connected Android Wear device, otherwise there isn't.
Update: With the release of Google Play Services 7.3, support for multiple Android Wear devices connected simultaneously has been added. You can use the CapabilityApi
to request nodes with specific capabilities.
Detecting connected/disconnected android wear device
Why not using CapabilitApi? If your app on the mobile provides a certain capability that you are interested in, you can use these apis to query for the nodes (connected and nearby) that provide that capability. Isn't that what you want?
kotlin: What is the best way to know if there is a wearos device connected to the phone and if it has a specific app installed?
You should be able to use the NodeClient to see if there is a wear device connected to your mobile.
https://developers.google.com/android/reference/com/google/android/gms/wearable/NodeClient
And then use CapabilityClient to see if you app is installed and advertising and agreed capability.
https://developers.google.com/android/reference/com/google/android/gms/wearable/CapabilityClient
If it's an unrelated app then you likely can't check whether it is installed remotely.
Detecting connected watch version
There's not a good way to do this right now. It's been discussed a couple of times on the Wear developers G+ community, and the best we came up with is:
- Go ahead and send the
RemoteIntent
to open the Play store. - Attach a
RemoteIntent.ResultReceiver
when you do so. - If the watch is running Wear 1.x, this will return with a
resultCode
ofRESULT_FAILED
, and you can show your user a message accordingly.
This is obviously not ideal; it involves a useless step (trying to open the Play store) for 1.x users, and there's also no way to distinguish any other possible failure modes. But as of today, it's the best we have.
Discussions:
https://plus.google.com/+SterlingUdell/posts/XJZ8mAsaZ8B
https://plus.google.com/u/0/+SterlingUdell/posts/WWBVxjcD7vT
Check android wear and mobile connection status
Wearable.NodeApi.getConnectedNodes returns a list of Nodes representing either the connected handheld (if called from the Wear app) or connected Wear devices (if called on the handheld). The list should be empty if there is no connection. Google has a short example here.
Related Topics
How to Use Tabhost.Ontabchangelistener in Android
Android - Detect End of Long Press
Mediametadataretriever Setdatasource Throws Illegalargumentexception
Method to Get All Edittexts in a View
Android Sp VS Dp Texts - What Would Adjust the 'Scale' and What Is the Philosophy of Support
Mediaplayer.Setdatasource() and Prepare() Not Working - Android
Android Error - Caused By: Java.Lang.Noclassdeffounderror: Android.Support.V4.Util.Sparsearraycompat
Firebase Authentication State Change Does Not Fire When User Is Disabled or Deleted
Android - How to Check If Developer Option Is Enabled
How to Hide the Share Action (Which Use Most) Icon Near the Share Action Provider
How to Change Actionmode Background Color in Android
Open a Selected File (Image, PDF, ...) Programmatically from My Android Application