您好,我有健身应用程序,我必须连接 google fit 并将我的健身应用程序数据共享到 google fit,我必须提供断开连接的选项。
我使用以下代码断开连接。
Fitness.getConfigClient(this, GoogleSignIn.getLastSignedInAccount(this)).disableFit();
一旦我禁用无法重新连接。如果尝试将数据上传到 google fit,我会遇到以下错误。
There was a problem reading the data. com.google.android.gms.common.api.ApiException: 4: The user must be signed in to make this API call.
最佳答案
在重新连接 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
}
关于android - 如何重新连接到 google fit in android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49106474/