cph-cachet / flutter-plugins

A collection of Flutter plugins developed by CACHET
551 stars 681 forks source link

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

Open winninggodspower opened 4 months ago

winninggodspower commented 4 months 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 4 months 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 4 months 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 4 months ago

same here on android 13

yogeshButani commented 4 months ago

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

figureai commented 3 months ago

same here on android 13

jbarszczewski commented 3 months 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!

AmmarTN commented 1 month ago

[health: ^11.1.0] still got the same error message "Permission launcher not found" even after adding implementation "androidx.health.connect:connect-client:1.1.0-alpha02" Android 12

any solutions ?

Thanks

lukepighetti commented 1 month ago

getting this issue on Health 11.0.0, but it may be some configuration issue that I'm not aware of

nektar95 commented 4 weeks ago

I was facing the same problem, solution is hidden in documentation. You need to change your MainActivity from FlutterActivity to FlutterFragmentActivity. Documentation may leading to confusion, with Android 14 in header where it's mentioned.

ling350181 commented 3 weeks ago

I am facing the same problem, also added in build.gradle implementation "androidx.health.connect:connect-client:1.1.0-alpha02" But there is no problem for Android 13 or higher, below 13 still can't have a permission request