imdzx / flutter_health_connect

MIT License
3 stars 24 forks source link

PlatformException UNABLE_TO_START_ACTIVITY when asking for permission in debug #15

Open hartmannj opened 1 year ago

hartmannj commented 1 year ago

OS: Android 14 Device: Emulator (Pixel 7 Pro, Android SDK 34 Google Play)

When trying to request for permissions like following:

await HealthConnectFactory.requestPermissions(
      [HealthConnectDataType.BloodGlucose],
);

the app crashes with exception:

Unhandled Exception: PlatformException(UNABLE_TO_START_ACTIVITY, No Activity found to handle Intent 
{ act=androidx.activity.result.contract.action.REQUEST_PERMISSIONS (has extras) }, 
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=androidx.activity.result.contract.action.REQUEST_PERMISSIONS (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2239)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1878)
at android.app.Activity.startActivityForResult(Activity.java:5589)
at android.app.Activity.startActivityForResult(Activity.java:5547)
at dev.duynp.flutter_health_connect.FlutterHealthConnectPlugin.onMethodCall(FlutterHealthConnectPlugin.kt:127)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
...

My AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <queries>
        <package android:name="com.google.android.apps.healthdata" />
    </queries>

    <uses-permission android:name="android.permission.health.READ_BLOOD_GLUCOSE"/>
    <uses-permission android:name="android.permission.health.WRITE_BLOOD_GLUCOSE"/>

    <application
        android:label="my_app"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />

            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <intent-filter>
                <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

The Health Connect app is installed on the emulator. Any idea what I am missing?

hartmannj commented 1 year ago

It seems to work with emulators using Android SDK 33 Google Play. This could potentially mean that it will crash on all devices with Android 14, or it is a bug in the SDK 34 Google Play emulator image.

ndubbaka commented 8 months ago

Is it because https://developer.android.com/health-and-fitness/guides/health-connect/migrate/migrate-from-android-13-to-14

In Android 13, you declare permissions using a custom permissions format, in a resource file that is linked to the manifest: To support Android 14, developers need to move to the standard permissions format:

image