GoogleApiClient onConnected never called on Wearable device

前端 未结 3 611
逝去的感伤
逝去的感伤 2020-12-16 09:13

I have a wearable device that I\'m trying to connect to the GoogleApiClient but the callbacks are never called (onConnected, onConnectionSuspended or onConnectionFailed). Ev

相关标签:
3条回答
  • 2020-12-16 09:48

    Additionally, I noticed that if you try to do GoogleApiClient when user hasn't setup Google Play there can be a conflict connecting. (I just reset my device and that's what happened). So it's a good practice to test connection from GoogleApiClient using

    mCredentialsApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
    

    Or just check mCredentialsApiClient.isConnected() before peforming any task.

    0 讨论(0)
  • 2020-12-16 09:49

    Oh wow, the answer is embarrassingly simple. I missed the part where in onStart() you need to call mGoogleApiClient.connect().

    0 讨论(0)
  • 2020-12-16 10:04

    You can call the connect and disconnect manually in the onStart and onStop lifecycle methods, or you can use the enableAutoManage feature.

    mCredentialsApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .enableAutoManage(this, this)
                .addApi(Auth.CREDENTIALS_API)
                .build();
    
    0 讨论(0)
提交回复
热议问题