如何解决Google Fit关联应用的权限已撤销应用仍然“已连接”
- 我将我的应用连接到Google Fit Tracker
- 该应用程序在与GoogleFit Tracker连接的应用程序标签中可见
- 我从GoogleFit中已连接的应用程序中删除了应用程序
- 我完全关闭了我的应用程序
- 我打开我的应用程序,我的应用程序中的Google Fit api无法识别到没有更多连接。
代码:
fun makeRequest(dataReadRequest: DataReadRequest): Single<DataReadResponse> {
val signInAccount: GoogleSignInAccount? = googleFitConnector.signInAccount()
return Single.create<DataReadResponse> { emitter ->
signInAccount?.let { account ->
fetchResponse(account,emitter,dataReadRequest)
}
}
.subscribeOn(schedulerProvider.newThread())
}
private fun fetchResponse(
account: GoogleSignInAccount,emitter: SingleEmitter<DataReadResponse>,dataReadRequest: DataReadRequest
) {
googleFitConnector.historyClient(account)
.readData(dataReadRequest)
.addOnCompleteListener { task ->
getResultOfTask(emitter,task)
}
}
fun getResultOfTask(emitter: SingleEmitter<DataReadResponse>,task: Task<DataReadResponse>) {
try {
task.result?.let { dataReadResponse ->
if (dataReadResponse.status.isSuccess) {
emitter.onSuccess(dataReadResponse)
} else {
emitter.onError(GoogleFitException.DataReadException(dataReadResponse))
}
}
task.exception?.let { exception ->
emitter.onError(GoogleFitException.DataReadExceptionWithOutResponse(exception))
}
} catch(exception: RuntimeExecutionException){
if(exception.message?.contains(GOOGLE_FIT_API_EXCEPTION_USER_NOT_SIGNED_IN) == true)
emitter.onError(GoogleFitException.GoogleFitConnectionLost(exception))
}
}
即使我们在GoogleFit应用中断开了该应用的连接,也要在返回该应用时
dataReadResponse.status.isSuccess
产生true
有时,我们会遇到com.google.android.gms.common.api.ApiException: 4: The user must be signed in to make this API call
异常,但并非每次执行上述步骤时都会发生。
问题 是否有可靠的方法来判断该应用程序是否已与Google Fit api断开连接?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。