Wearable.NodeApi.getConnectedNodes result never called

后端 未结 4 2460
情歌与酒
情歌与酒 2021-02-20 05:56

i developing an app for android wear. Below code with explanation of the problem

 if(mGoogleApiClient.isConnected()){
            K.i(\"Always called!\");
               


        
4条回答
  •  日久生厌
    2021-02-20 06:16

    Here's a full code of how to check it:

    add this to the gradle file:

    compile 'com.google.android.gms:play-services-wearable:9.4.0'
    

    And use this function to check if a wearable is connected:

    @WorkerThread
    public boolean isWearableAvailable(Context context) {
        NotificationManagerCompat.from(context).cancel(NotificationType.WEARABLE_IN_CALL.getId());
        final GoogleApiClient googleApiClient = new Builder(context).addApi(Wearable.API).build();
        final ConnectionResult connectionResult = googleApiClient.blockingConnect();
        if (connectionResult.isSuccess()) {
            NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
            for (Node node : nodes.getNodes()) {
                if (node.isNearby()) 
                    return true;
            }
        }
        return false;
    }
    

提交回复
热议问题