在docs中所述的IllegalArgumentException
尝试与GoogleFit断开连接时获得Fitness.ConfigApi.disableFit(mClient)
。我能够连接和检索历史数据a-ok。
错误
GoogleApiClient未配置为使用此所需的API 打电话。
在com.google.android.gms.common.internal.zzaa.zzb(未知来源)
禁用/断开代码(注意我在调用之前检查了mClient.isConnected()
):
PendingResult<Status> pendingResult = Fitness.ConfigApi.disableFit(mClient);
pendingResult.setResultCallback(new ResolvingResultCallbacks<Status>(this, RC_DISCONECT_GOOGLE_FIT) {
@Override
public void onSuccess(@NonNull Status status) {
updateStatus("Disconnected from Google Fit: " + status.getStatusMessage());
}
@Override
public void onUnresolvableFailure(@NonNull Status status) {
updateStatus("Error disconnecting from Google Fit: " + status.getStatusMessage());
}
});
GoogleApiClient配置
private void buildFitnessClient() {
mClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.HISTORY_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE)).build();
}
使用&#39; com.google.android.gms定位API 23,在API 21上运行:play-services-fitness:9.0.1&#39;
答案 0 :(得分:1)
当您构建GoogleApiClient
时,必须添加.addApi(Fitness.CONFIG_API)
才能使用Fitness.ConfigApi.disableFit(mClient)
。哪个有意义只是扔了我,因为它从文档中丢失。
mClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.HISTORY_API)
.addApi(Fitness.CONFIG_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE)).build();