Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Google Fit and revoke permissions from the app itself

I've setup app that connects to Google Fit, reads and writes some data about users body. When user disables Google Fit in apps settings, I try to revoke my apps permissions for by calling:

public void disableGoogleFit(){
    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);
            }
        }
    });
}

Even though I could successfully read/write data, disabling Fit returns me error:

Google Fit wasn't disabled Status
{statusCode=unknown status code: 5010, resolution=null}

Edit1: Added whole method, in which its visible, that client is connected at the moment I try do disable Fit.

like image 907
Jaroslav Avatar asked Nov 25 '14 15:11

Jaroslav


People also ask

Can I delete Google Fit?

Delete your Google Fit dataAt the bottom, tap Profile. Tap Manage your data. "Delete All." Confirm you want to delete the data.


1 Answers

Currently with 15.0.1 lib it can be easily done:

fun disconnect(context: Context) {
    val fitnessOptions = FitnessOptions.builder()
            .addDataType(DataType.TYPE_WORKOUT_EXERCISE, FitnessOptions.ACCESS_READ)
            .build()
    val signInOptions = GoogleSignInOptions.Builder().addExtension(fitnessOptions).build()
    val client = GoogleSignIn.getClient(context, signInOptions)
    client.revokeAccess()
}
like image 65
a.ch. Avatar answered Oct 16 '22 00:10

a.ch.