'Revoke permissions
I've been playing around with google fit, and have issues revoking the permissions that I've previously been granted.
This is how I check if permissions have been granted, and request permissions if they have not.
private val fitnessOptions = FitnessOptions.builder()
.addDataType(DataType.TYPE_WEIGHT, FitnessOptions.ACCESS_READ)
.addDataType(DataType.AGGREGATE_WEIGHT_SUMMARY, FitnessOptions.ACCESS_READ)
.build()
val account : GoogleSignInAccount = GoogleSignIn.getAccountForExtension(activity, fitnessOptions)
if (!GoogleSignIn.hasPermissions(account, fitnessOptions)) {
GoogleSignIn.requestPermissions(
activity,
GOOGLE_FIT_PERMISSIONS_REQUEST_CODE,
account,
fitnessOptions)
}
This page talks about using ConfigClient.disableFit to disconnect, but it doesn't seem to work.
This thread describes the problem really well, and the comments resemble some of the things I've tried as well. The solution doesn't work, I get the same error as krokyze. I can log out the user using GoogleSignInClient.signOut but if I log in to the same account again, the permissions are still granted.
Disconnecting my app through the GoogleFit app seems to work, but it's not great UX to ask the user to do it that way. I've also encountered some sync issues doing that. I would disconnect the app, reconnect and get permissions, but my app wouldn't show up in GoogleFit's list of connected apps for a long time.
Solution 1:[1]
For revoking permissions you can use following method
val options = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.addExtension(getFitnessOptions())
.requestProfile()
.build()
GoogleSignIn.getClient(this, options).revokeAccess()
Solution 2:[2]
I solved this by calling the API in the following order
- revoke permissons
- disable Fit
The sample code is as follows:
val signInOptions = GoogleSignInOptions.Builder()
.addExtension(fitnessOptions)
.build()
GoogleSignIn.getClient(requireActivity(), signInOptions)
.revokeAccess()
.continueWith {
Fitness.getConfigClient(
requireActivity(),
GoogleSignIn.getAccountForExtension(requireContext(), fitnessOptions)
)
.disableFit()
}
.addOnSuccessListener {
// handle success case
}
.addOnFailureListener {
// handle failed case
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | sela |
| Solution 2 | Yutaka KATO |
