gpt4 book ai didi

android - 未请求适当的 Api。断开与 Google 健身的连接

转载 作者:行者123 更新时间:2023-11-29 15:09:24 24 4
gpt4 key购买 nike

我在与 google fit 断开连接时收到 null pinter 异常

E/AndroidRuntime: java.lang.NullPointerException: Appropriate Api was not requested.
E/AndroidRuntime: at com.google.android.gms.common.internal.zzx.zzb(Unknown Source)
E/AndroidRuntime: at com.google.android.gms.internal.zzli.zza(Unknown Source)
E/AndroidRuntime: at com.google.android.gms.internal.zzlf.zza(Unknown Source)
E/AndroidRuntime: at com.google.android.gms.internal.zzlf.zzb(Unknown Source)
E/AndroidRuntime: at com.google.android.gms.internal.zzli.zzb(Unknown Source)
E/Androi

这是我断开连接的代码

public void disableGoogleFit(GoogleApiClient mClient) {
if (!mClient.isConnected()) {
Log.e(TAG, "Google Fit wasn't connected");
return;
}
PendingResult<Status> pendingResult = Fitness.ConfigApi.disableFit(mClient);

pendingResult.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.i(TAG, "Google Fit disabled");
} else {
Log.e(TAG, "Google Fit wasn't disabled " + status);
}
}
});
}

最佳答案

构建GoogleApiClient时需要添加ConfigApi,如下所示。

new GoogleApiClient.Builder(context)
.addApi(Fitness.HISTORY_API)
.addApi(Fitness.SESSIONS_API)
.addApi(Fitness.CONFIG_API)

就是这样。

关于android - 未请求适当的 Api。断开与 Google 健身的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33276402/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com