【问题标题】:How to reconnect to google fit in android如何重新连接到 google fit in android
【发布时间】:2018-08-12 20:57:05
【问题描述】:

您好,我有健身应用,我必须连接 google fit 并将我的健身应用数据分享到 google fit,并且我必须提供断开连接的选项。

我正在使用以下代码断开连接。

Fitness.getConfigClient(this, GoogleSignIn.getLastSignedInAccount(this)).disableFit();

一旦我禁用无法重新连接。如果尝试将数据上传到 google fit,我会遇到以下错误。

读取数据时出现问题。 com.google.android.gms.common.api.ApiException: 4: 用户必须登录才能进行此 API 调用。

【问题讨论】:

    标签: android google-fit google-fit-sdk


    【解决方案1】:

    一旦您拥有disconnected from Google Fit,它就会撤消您应用的所有授予 OAuth 权限,并删除您的应用进行的所有录制订阅和传感器注册。您应该在应用设置中为用户提供与 Google Fit 的断开连接选项。建议的操作是重新启动应用程序本身。当调用 Google Play 服务失败时发生异常。你需要reconnect to the fitness service

    【讨论】:

      【解决方案2】:

      在重新连接 google fit api 之前尝试此代码

        GoogleSignInAccount account = GoogleSignIn.getAccountForExtension(HeartRateCountActivity.this, fitnessOptions);
                          // all fields of account are empty
      
                          if (!GoogleSignIn.hasPermissions(account, fitnessOptions)) {
                              Log.i(TAG, "Asking for permission");
                              GoogleSignIn.requestPermissions(
                                     HeartRateCountActivity. this,
                                      001,
                                      account,
                                      fitnessOptions
                              );
                          } else { // this branch is executed which is weird
                              Log.i(TAG, "Already has permissions");
                  //writer your code here
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-12-29
        • 2022-11-11
        • 1970-01-01
        • 1970-01-01
        • 2015-02-10
        • 1970-01-01
        • 2017-03-24
        相关资源
        最近更新 更多