Determine if your Android Wear device is turned on

I am developing an Android app that also uses notifications on an Android Wear device. For my application functionality, it’s important to know whether a Wear device is connected or not, and this cannot be determined.

I tried the following:

  • Using Nodelistener API. I want to do something simple - for example, restart the clock and see that it is disconnected online, but I do not receive these events. I read that it is only hardcore pairing / unlocking of the clock that causes these events to be sent (which seems wrong imo, and it is too complicated to illustrate the purpose of my application). I also read this post ( https://plus.google.com/+NathanSchwermann/posts/1Rs9etY5qte ), but I already use WLS in my application.
  • Instead, a bluetooth listener is used (Broadcastreceiver listens for BluetoothDevice.ACTION_ACL_CONNECTED and DISCONNECTED actions), which works fine, except that I cannot determine if this Wear device is connected. Again, this is because of NodeApi: Wearable.NodeApi.getConnectedNodes (wearApiClient) .setResultCallback ... never gets a result callback. This is what I'm trying to do when you do ACION_ACL_CONENCTED, by the way - and then I just want to see how many nodes are connected and determine if it has recently connected node.

So, none of this comes out, and I have no ideas. NodeApi seems to be not working as the developer wants to use it, and I really need this functionality.

Does anyone know a smart way around this?

** UPDATE: **

, , .

+4
3

, , List<Node> connectedNodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await().getNodes();
, Google Glass node, , - Google Glass, , 2 , .

+1

"", :

List<Node> connectedNodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await().getNodes();

, wait() (, ):

Wearable.NodeApi.getConnectedNodes(wearApiClient).setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
    @Override
    public void onResult(NodeApi.GetConnectedNodesResult getConnectedNodesResult) {
        List<Node> nodes = getConnectedNodesResult.getNodes();
        // Do your stuff with connected nodes here
    }
});

, ResultCallback , ( getConnectedNodes()), , .

+1

I am using a much simpler method suitable for my use, check if android android application is installed:

    try {
        getPackageManager().getPackageInfo("com.google.android.wearable.app", PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException e) {
        //android wear app is not installed
    }
0
source

All Articles