GoogleApiClient onConnected never called on Wearable device

好久不见. 提交于 2019-11-29 02:48:51
odiggity

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

Imre

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();

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!