【发布时间】:2017-06-17 22:31:33
【问题描述】:
我想手动处理GoogleApiClient 上的connect() 和disconnect() 操作。我正在尝试:
- 建立一个新的
GoogleApiClient(没有enableAutoManage) - 致电
connect() - 当
onConnected()被调用时执行signOut - 在
signOut结束后致电disconnect()
这是一个例子:
fun signOut(googleApiClient: GoogleApiClient, resultCallback: (Status) -> Unit) {
Auth.GoogleSignInApi.signOut(googleApiClient).setResultCallback(resultCallback)
}
fun test() {
val googleApiClient = GoogleApiClient.Builder(activity)
.addApi(Auth.GOOGLE_SIGN_IN_API, buildGoogleSignInOptions(googleAuthId))
.build()
googleApiClient.registerConnectionCallbacks(object : ConnectionCallbacks {
override fun onConnected(connectionHint: Bundle?) {
signOut { status ->
//TODO something with status
googleApiClient.disconnect()
}
}
override fun onConnectionSuspended(cause: Int) {
//nop
}
})
googleApiClient.registerConnectionFailedListener {
//TODO handle failure
}
googleApiClient.connect()
}
但是,当onConnected() 被调用时,signOut 调用失败并显示
IllegalStateException: GoogleApiClient is not connected yet
我做错了什么还是图书馆的错误?
【问题讨论】:
-
这个SO thread的错误似乎是一样的并且已经解决了。
-
@noogui 谢谢!在
onCreate()中移动客户端创建听起来更像是一种解决方法而不是解决方案,但我想我无能为力了。正如在这个帖子中所说,没有办法向谷歌报告这个错误......
标签: android google-play-services kotlin google-signin