Skip to content

[Health][Android] Rejected authorization request never returns #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TylerStein opened this issue Jul 29, 2020 · 1 comment
Closed

[Health][Android] Rejected authorization request never returns #133

TylerStein opened this issue Jul 29, 2020 · 1 comment

Comments

@TylerStein
Copy link

TylerStein commented Jul 29, 2020

Plugin name & version
Health 1.1.4

Describe the bug
The invoked requestAuthorization plugin method on Android never returns the Future if the user does not complete authorization with their Google account.

To Reproduce
Steps to reproduce the behavior:

  1. Run an app that calls Health.requestAuthorization() on Android
  2. Tap off of the Google account dialog to cancel the authorization process
  3. See that the _channel.invokeMethod('requestAuthorization') Future is never returned

Expected behavior
Invoking requestAuthorization should at least return false when the user cancels the authorization request by closing the Google account dialog.

Actual behavior
Invoking requestAuthorization and closing the Google account dialog without authorizing never returns the Future created in the Health.requestAuthorization() method.

Screenshots

Flutter doctor
[√] Flutter (Channel stable, v1.17.4, on Microsoft Windows [Version 10.0.18362.959], locale en-CA)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[√] Android Studio (version 3.6)
[√] Connected device (1 available)
• No issues found!

Smartphone(s) / Emulator

  • Device: Samsung Galaxy S8 (SM-G950W)
  • OS: Android 9 (Kernel 4.4.153-17901174)

Additional context
I managed to solve the issue in a local copy of the plugin code by updating the onActivityResult method of HealthPlugin.kt
The change is in this pull request #134

class HealthPlugin(val activity: Activity, val channel: MethodChannel) : MethodCallHandler, ActivityResultListener, Result {
...
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean {
        if (requestCode == GOOGLE_FIT_PERMISSIONS_REQUEST_CODE) {
            if (resultCode == Activity.RESULT_OK) {
                Log.d("FLUTTER_HEALTH", "Access Granted!")
                mResult?.success(true)
            } else if (resultCode == Activity.RESULT_CANCELED) {
                Log.d("FLUTTER_HEALTH", "Access Denied!")
                mResult?.success(false);
            }
        }
        return false
    }
...
}
TylerStein pushed a commit to TylerStein/flutter-plugins that referenced this issue Jul 29, 2020
thomasnilsson pushed a commit that referenced this issue Jul 30, 2020
#133 Handle RESULT_CANCELED in HealthPlugin.kt onActivityResult
@thomasnilsson
Copy link
Contributor

Merged the pull request and the changes are not live in version 1.1.5, thank you!

hibitness-quan-nguyen2 pushed a commit to hibitness/flutter-plugins that referenced this issue Dec 18, 2023
hibitness-quan-nguyen2 pushed a commit to hibitness/flutter-plugins that referenced this issue Dec 18, 2023
cph-cachet#133 Handle RESULT_CANCELED in HealthPlugin.kt onActivityResult
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants