Google Fit关联应用的权限已撤销应用仍然“已连接”

问题描述

  1. 我将我的应用连接到Google Fit Tracker
  2. 该应用程序在与GoogleFit Tracker连接的应用程序标签中可见
  3. 我从GoogleFit中已连接的应用程序中删除了应用程序
  4. 我完全关闭了我的应用程序
  5. 我打开我的应用程序,我的应用程序中的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 (将#修改为@)