GoogleSignIn.hasPermissions always return true even if I call disableFit
See original GitHub issueIssue 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:
- Created 4 years ago
- Reactions:8
- Comments:13
Top GitHub Comments
it’s year 2022, still the same issue
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:
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?