cph-cachet / flutter-plugins

A collection of Flutter plugins developed by CACHET
540 stars 647 forks source link

[health: ^10.2.0] Permission launcher not found #1001

Open winninggodspower opened 1 month ago

winninggodspower commented 1 month ago

i keep getting Permission launcher not found when trying to request android health connect permission

Device / Emulator and OS

i'm emulating on a physical device

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

made the initial setup following the instruction from the read me. i have a button that calls this function

`Future authorize() async { final permissions = [ Permission.activityRecognition, Permission.location, ];

await permissions.request();

bool? hasPermissions =
    await Health().hasPermissions(health_settings.types, permissions: health_settings.permissions);
developer.log('has permission: $hasPermissions');

bool authorized = hasPermissions ?? false;
if (hasPermissions != true) {
  try {
    authorized = await Health()
        .requestAuthorization(health_settings.types, permissions: health_settings.permissions);
  } catch (error) {
    developer.log("Exception in authorize: $error");
  }
}
developer.log('is it authorized: $authorized');

// Update the global permission state
Provider.of<DevicePermissionProvider>(context, listen: false).setAuthorization(authorized);

setState(() => _state =
    (authorized) ? AppState.AUTHORIZED : AppState.AUTH_NOT_GRANTED);

}`

The "Health().requestAuthorization" call returns false, but then the Health().requestAuthorization keeps giving me this log👉 Permission launcher not found therefore the permission popup never shows up

in case you're wondering where the health_permission.type is coming from. it's from this file ` import 'package:health/health.dart';

var types = [ HealthDataType.STEPS, HealthDataType.HEART_RATE, HealthDataType.BODY_TEMPERATURE, HealthDataType.WEIGHT, HealthDataType.BLOOD_OXYGEN ];

List get permissions => types.map((e) => HealthDataAccess.READ).toList(); `

Expected behavior

show permission launcher

Actual behavior

doesn't show permission launcher

Screenshots

If applicable, add screenshots to help explain your problem.

Flutter doctor

Please run flutter doctor and add the output here.

Additional information

my manifest file `

`

Screenshot 2024-07-09 150239

yogeshButani commented 1 month ago

hii @winninggodspower i have also used health package to get the steps data from health connect. On IOS devices it's working good, taking data from apple health successfully but when comes in android, its always showing 0 steps, i have all the setup for Android, even not getting any type of error still showing 0 steps don't know why...all permissions are enabled, app is also showing inside health connect settings on device...don't know how the issue is occurring... please help

Did you also facing the same issue? please revert

yogeshButani commented 1 month ago

my android manifest looks like below <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.cwt.testhealthapp">

<queries>
    <package android:name="com.google.android.apps.healthdata" />
    <intent>
        <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
    </intent>
</queries>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Permissions for new android API (Health Connect) -->
<uses-permission android:name="android.permission.health.READ_STEPS" />
<uses-permission android:name="android.permission.health.WRITE_STEPS" />

<application
    android:name="${applicationName}"
    android:icon="@mipmap/ic_launcher"
    android:label="testhealthapp">
    <activity
        android:name=".MainActivity"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:exported="true"
        android:hardwareAccelerated="true"
        android:launchMode="singleTop"
        android:taskAffinity=""
        android:theme="@style/LaunchTheme"
        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>

        <!-- Intention to show Permissions screen for Health Connect API -->
        <intent-filter>
            <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
        </intent-filter>

    </activity>
    <activity-alias
        android:name="ViewPermissionUsageActivity"
        android:exported="true"
        android:permission="android.permission.START_VIEW_PERMISSION_USAGE"
        android:targetActivity=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.VIEW_PERMISSION_USAGE" />
            <category android:name="android.intent.category.HEALTH_PERMISSIONS" />
        </intent-filter>
    </activity-alias>

    <!-- 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>
<!-- Required to query activities that can process text, see:
     https://developer.android.com/training/package-visibility and
     https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.

     In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
<queries>
    <intent>
        <action android:name="android.intent.action.PROCESS_TEXT" />
        <data android:mimeType="text/plain" />
    </intent>
</queries>

hutomosaktikartiko commented 1 month ago

same here on android 13

yogeshButani commented 1 month ago

hii @hutomosaktikartiko did you facing the same issue? please tell me if your issue get resolved

figureai commented 1 month ago

same here on android 13

jbarszczewski commented 2 weeks ago

I've had similar issue, and I've found that my project was missing this (comparing to their example but omitted in documentation) in build.gradle:

dependencies {
    // The old fitness api
    // def composeBom = platform('androidx.compose:compose-bom:2022.10.00')
    // implementation(composeBom)
    // implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    // testImplementation 'junit:junit:4.12'
    // implementation("com.google.android.gms:play-services-fitness:21.1.0")
    // implementation("com.google.android.gms:play-services-auth:20.2.0")
    // The new health connect api
    implementation "androidx.health.connect:connect-client:1.1.0-alpha02"
}

I'm testing on android 14 and last line is enough but original Health example had the old api uncommented instead. Hope it helps!