googlearchive / android-fit

Migrated:

Home Page:https://github.com/android/fit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GoogleSignIn.hasPermissions always return true even if I call disableFit

opened this issue · comments

Hi,

The situation

I'm trying to enable/disable google fit in my app with a Switch View.

When I turn off this switch, I call below code.

Fitness.getConfigClient(context, account).disableFit()
                .addOnSuccessListener {
                    Timber.d("disconnectGoogleFit: onSuccess")
                }
                ...

After onSuccess, I turn on switch to connect google fit and call below.

if (GoogleSignIn.hasPermissions(GoogleSignIn.getLastSignedInAccount(this), fitnessOptions){
 return
}
GoogleSignIn.requestPermissions(
        this, // your activity
        GOOGLE_FIT_PERMISSIONS_REQUEST_CODE,
        GoogleSignIn.getLastSignedInAccount(this),
        fitnessOptions);

Nothing happens because GoogleSignIn.hasPermissions always return true.

What I want to do

I'd like to check whether Google fit permission is granted or not before calling GoogleSignIn.requestPermissions

Please tell me how to do this.

Thank you


Update

I think I have found a solution that disconnecting app through Google Fit App. After this, GoogleSignIn.hasPermissions return false.
But I am curious how can do this programmatically.

Solved

GoogleSignInClient.revokeAccess works. I don't know the reasons why.

 val signInOptions = GoogleSignInOptions.Builder().addExtension(fitnessOptions).build()
            val client = GoogleSignIn.getClient(context, signInOptions)
            client.revokeAccess()
                .addOnSuccessListener {
                    Timber.d("disconnectGoogleFit: onSuccess")
                }

Question

I'd like to ask you what is the diffrences between Fitness.getConfigClient(context, account).disableFit() and GoogleSignInClient.revokeAccess?

Thank you

I've tried this but keep getting NullPointerException: Attempt to invoke interface method 'int com.google.android.gms.auth.api.signin.GoogleSignInOptionsExtension.getExtensionType()' on a null object reference

I am closing this issue/PR, as it has been migrated to the new repo linked above in the comments. Thank you!