I am getting a null pinter exception while am disconnecting from google fit
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
This is my code to disconnecting
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);
}
}
});
}
You need to add ConfigApi
when you building GoogleApiClient
Like below.
new GoogleApiClient.Builder(context)
.addApi(Fitness.HISTORY_API)
.addApi(Fitness.SESSIONS_API)
.addApi(Fitness.CONFIG_API)
Thats it .