没有请求适当的 Api。与 Google Fit 断开连接

Appropriate Api was not requested. Disconnect from Google Fit

我在与 google fit

断开连接时收到空 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);
            }
        }
    });
}

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

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

就是这样。