imdzx / flutter_health_connect

MIT License
3 stars 26 forks source link

PlatformException when Health Connect is not installed #10

Open koenmuilwijk opened 1 year ago

koenmuilwijk commented 1 year ago

When Google Health Connect is not installed on the device the plugin gives the following exception when calling any method (including the HealthConnectFactory.isApiSupported() method. I verified this same behaviour happens in the provided example app.

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(NO_ACTIVITY, No activity available, null, null)

This is because there is no activityContext available while this is asserted on line 71 in FlutterHealthConnectPlugin.kt.

I believe the correct behaviour would be to not require the activityContext for the following method calls: isApiSupported, isAvailable, and installHealthConnect.

owjoh commented 1 year ago

@koenmuilwijk Did you ever figure out a work-around?

koenmuilwijk commented 1 year ago

@owjoh not really, no.

I have this hacky workaround which is far from perfect. However, this library seems not able to work in production atm (see the other ticket on that) so that's the next show stopper you'll run into.

static installHealthConnect() async {
    //return HealthConnectFactory.installHealthConnect();
    launchUrl(
      Uri.parse("market://details?id=com.google.android.apps.healthdata"),
      mode: LaunchMode.externalApplication,
    );  
  }

And then wrap the isApiSupported and isAvailable into try-catch's.

Fethi-Hamdani commented 2 months ago

Any updates on This?