4

Hi I've fitness app I have to connect google fit and share my fitness app data to google fit and I've to give option to disconnect.

I'm disconnecting by using below code.

Fitness.getConfigClient(this, GoogleSignIn.getLastSignedInAccount(this)).disableFit();

Once I disable unable to reconnect. if try upload data to google fit I'm getting below error.

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.

Aftab H.
  • 1,517
  • 4
  • 13
  • 25

2 Answers2

1

try this code before reconnect 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
}
white hills
  • 237
  • 1
  • 8
0

Once you have disconnected from Google Fit, it revokes all granted OAuth permissions for your app and removes all recording subscriptions and sensor registrations made by your app. You should provide users with a Disconnect from Google Fit option in your app settings. Suggested action is to restart the app itself. The exception occurred when a call to Google Play services has failed. You need to reconnect to the fitness service.

abielita
  • 13,147
  • 2
  • 17
  • 59