question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GoogleSignIn.hasPermissions always return true even if I call disableFit

See original GitHub issue

Issue by norio-agoop Wednesday Mar 27, 2019 at 09:06 GMT _Originally opened as https://github.com/googlesamples/android-fit/issues/48_


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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:8
  • Comments:13

github_iconTop GitHub Comments

13reactions
lyw-94commented, Jan 17, 2022

it’s year 2022, still the same issue

4reactions
krokyzecommented, Nov 24, 2019

Hey,

so I was trying to achieve that user can easily log out from previously selected account and just using disableFit() or revokeAcess() didn’t work. The only working solution that I found was doing like this:

val fitnessOptions = FitnessOptions.builder()
                .build()
        
Fitness.getConfigClient(context, GoogleSignIn.getLastSignedInAccount(context))
                .disableFit()
                .continueWithTask {
                    val signInOptions = GoogleSignInOptions.Builder()
                            .addExtension(fitnessOptions)
                            .build()
                    GoogleSignIn.getClient(context, signInOptions)
                            .revokeAccess()
                }
                .addOnFailureListener { e ->
                    // receives error with no message and status code 4
                }

Failure return status code with value 4 which is SIGN_IN_REQUIRED and next time when requesting permissions user is able to select an account.

Shouldn’t just using disableFit achieve this result?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Sign in request to use Fitness API is always failing
I can see an account selector dialog on running this code. I get the failure code in onActivityResult on selecting an account from...
Read more >
GoogleSignIn | Google Play services
Determines if the given account has been granted permission to all scopes associated with the given extension. static boolean. hasPermissions( ...
Read more >
Unexpected error. [128898656] - Visible to Public - Issue Tracker
Google Fit API (History API) on WearOS constantly return error, ... If you run the same code on the android phone, then everything...
Read more >
Manage Google Fit's permissions - Android
When you turn on certain permissions, Google Fit can better track your activities and give you better info about your fitness and activity....
Read more >
com.google.android.gms.auth.api.signin.GoogleSignIn ...
int resultCode, Intent data) { ; super.onActivityResult(requestCode, resultCode, data); ; if (requestCode == RC_SIGN_IN) { ; // The Task returned from this call...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found