如何在安卓设备上重新连接到Google Fit

4

你好,我有一个健身应用程序,我需要将其连接到Google Fit并共享我的健身应用程序数据到Google Fit,并提供断开连接的选项。

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

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

如果我禁用了重新连接,尝试上传数据到Google Fit时会出现以下错误:

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

2个回答

1

在重新连接 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
}

0

一旦您断开与Google Fit的连接,它将撤销您的应用程序授予的所有OAuth权限,并删除您的应用程序创建的所有记录订阅和传感器注册。您应该在应用程序设置中为用户提供与Google Fit的断开连接选项。建议的操作是重新启动应用程序本身。当调用Google Play服务失败时会发生异常。您需要重新连接到Fitness服务


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接