flutter-permission-handler icon indicating copy to clipboard operation
flutter-permission-handler copied to clipboard

[Bug]: Permission status return permanentlyDenied but the setting status actually is notify on Xiammi MIUI 12

Open RandallXia opened this issue 5 months ago • 1 comments

Please check the following before submitting a new issue.

Please select affected platform(s)

  • [X] Android
  • [ ] iOS
  • [ ] Windows

Steps to reproduce

  1. go to app setting, set the target permission status to notify
  2. request the target permission in dart code

Expected results

permission.status = notify

Actual results

permission.status = permanentlyDenied

Code sample

Code sample
    var cameraStatus = await Permission.camera.status;
    info("camera cameraStatus: $cameraStatus");

Screenshots or video

Screenshots or video demonstration

屏幕截图 2024-02-04 144806 屏幕截图 2024-02-04 145210

Version

11.2.0

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.16.9, on Microsoft Windows [版本 10.0.19045.3208], locale zh-CN)
    • Flutter version 3.16.9 on channel stable at C:\Softwares\Google\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 41456452f2 (10 days ago), 2024-01-25 10:06:23 -0800
    • Engine revision f40e976bed
    • Dart version 3.2.6
    • DevTools version 2.28.5

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Softwares\Google\Android\Android-SDK
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Softwares\Google\Android\apps\AndroidStudio\ch-1\223.8836.35.2231.11090377\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-10027231)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.4.3)
    • Visual Studio at C:\Softwares\Microsoft_Visual_Studio
    • Visual Studio Community 2022 version 17.4.33205.214
    • Windows 10 SDK version 10.0.22000.0

[√] Android Studio (version 2020.3)
    • Android Studio at C:\Softwares\Google\Android\Android_Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[√] Android Studio (version 2022.3)
    • Android Studio at C:\Softwares\Google\Android\apps\AndroidStudio\ch-1\223.8836.35.2231.11090377
    • Flutter plugin version 77.1.1
    • Dart plugin version 223.8977
    • android-studio-dir = C:\Softwares\Google\Android\apps\AndroidStudio\ch-1\223.8836.35.2231.11090377
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-10027231)

[√] IntelliJ IDEA Community Edition (version 2022.2)
    • IntelliJ at C:\Softwares\Google\Android\apps\IDEA-C\ch-0\222.4167.29
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart

[√] Connected device (5 available)
    • V2266A (mobile)        • 10ADBA0TJB003Z7 • android-arm64  • Android 14 (API 34)
    • Redmi K30i 5G (mobile) • 5bfacf3         • android-arm64  • Android 10 (API 29)
    • Windows (desktop)      • windows         • windows-x64    • Microsoft Windows [版本 10.0.19045.3208]
    • Chrome (web)           • chrome          • web-javascript • Google Chrome 120.0.6099.130
    • Edge (web)             • edge            • web-javascript • Microsoft Edge 89.0.774.54

[√] Network resources
    • All expected network resources are available.

RandallXia avatar Feb 04 '24 06:02 RandallXia

Dear @RandallXia,

Can you check if you also see this happening in the Example app?

Kind regards,

TimHoogstrate avatar Feb 12 '24 13:02 TimHoogstrate

Dear @RandallXia,

Can you check if you also see this happening in the Example app?

Kind regards,

It also happens in the Example app. image_descriptionimage_description

RandallXia avatar Feb 23 '24 06:02 RandallXia

I am also experiencing this on iOS 17. Camera and Microphone permissions return PermissionStatus.permanentlyDenied when requesting multiple permissions at once, but the device settings show those permissions as enabled (and in the app the camera still loads).

For context a previous plugin auto-requested these permissions, but permission_handler was added later on and is now interfering with already granted permissions.

jt274 avatar Feb 26 '24 18:02 jt274

I am also experiencing this on iOS 17. Camera and Microphone permissions return PermissionStatus.permanentlyDenied when requesting multiple permissions at once, but the device settings show those permissions as enabled (and in the app the camera still loads).

For context a previous plugin auto-requested these permissions, but permission_handler was added later on and is now interfering with already granted permissions.

I'm considering getting the true permission status from the native both Android & iOS through Pigeon.

RandallXia avatar Feb 27 '24 13:02 RandallXia

I have uninstalled and reinstalled the app. The issue persists on iOS 17. I am requesting multiple permissions at once:

Map<Permission, PermissionStatus> statuses = await [Permission.camera, Permission.location, Permission.microphone, Permission.storage,].request();

In this situation, the only request dialog to show up is the location. After selecting allow, location and storage return granted permissions, while camera and microphone return a permanently denied status.

jt274 avatar Feb 27 '24 17:02 jt274

I have tried older versions of the package back to 10.4.5, and tried requesting permissions one at a time, starting with the camera. I've uninstalled/reinstalled and no matter what I do, requesting the camera or microphone permissions return permanentlyDenied without ever showing a request screen. Other packages such as the camera can request permissions on their own and it works fine.

This is on iOS 17 and an iPhone 11 physical device. There is no issue I can see on Android.

jt274 avatar Feb 27 '24 18:02 jt274

@jt274 did you found any solution for it?

Tusharyadav147 avatar Mar 13 '24 06:03 Tusharyadav147

Hi @jt274 and @Tusharyadav147,

This can happen on iOS is the permissions are not enabled in the ios/Podfile as described in the "iOS" section of the README.md. Please read this carefully and make sure the correct configuration is applied.

If the problem still remains, please create a new issue in this repo as the original poster only has a problem on Android which is a different issue altogether

mvanbeusekom avatar Mar 13 '24 08:03 mvanbeusekom

Hi @RandallXia,

This might be an issue specifically related to MIUI 12 as I cannot reproduce it om my Xiaomi Redmi Note 9 device (running MIUI 13).

I have created a quick test application taking the following steps:

  1. Create new Flutter application: flutter create --platforms=ios issue_1275.
  2. Change into the project directory: cd issue_1275.
  3. Add a dependency on the latest permission_handler plugin: flutter pub add permission_handler.
  4. Add required configuration to the android/app/src/main/AndroidManifest.xml (see code below).
  5. Update the lib/main.dart to request Camera permission (see code below).
  6. Run the application and hit the floating action button to request permission, select "ONLY THIS TIME" (MIUI 13 option, see screenshot), the method returns "granted" in my case.

Code files:

android/app/src/main/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Permissions options for the `camera` group -->
    <uses-permission android:name="android.permission.CAMERA"/>

    <application
        android:label="issue_1275"
        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>
        </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>
    <!-- Required to query activities that can process text, see:
         https://developer.android.com/training/package-visibility?hl=en 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>
</manifest>

pubspec.yaml
name: issue_1275
description: "A new Flutter project."
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
  sdk: '>=3.3.1 <4.0.0'

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.6
  permission_handler: ^11.3.0

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^3.0.0

flutter:
  uses-material-design: true

lib/main.dart
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String _permissionStatus = PermissionStatus.denied.name;

  Future<void> _requestCameraPermission() async {
    final PermissionStatus permissionStatus = await Permission.camera.request();

    setState(() {
      _permissionStatus = permissionStatus.name;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'Full access camera status:',
            ),
            Text(
              _permissionStatus,
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _requestCameraPermission,
        tooltip: 'Request camera permission',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Screenshot of MIUI 13 permission request: Image

Here is the output of my flutter doctor -v command:

[✓] Flutter (Channel stable, 3.19.3, on macOS 14.3.1 23D60 darwin-arm64, locale en-US)
    • Flutter version 3.19.3 on channel stable at /Users/maurits/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ba39319843 (12 days ago), 2024-03-07 15:22:21 -0600
    • Engine revision 2e4ba9c6fb
    • Dart version 3.3.1
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/maurits/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

[✓] VS Code (version 1.87.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.84.0

[✓] Connected device (4 available)
    • M2003J15SC (mobile)                    • 106fdad20410              • android-arm64  • Android 12 (API 31)
    • Maurits van Beusekom’s iPhone (mobile) • 00008101-000D543E1A40001E • ios            • iOS 17.3.1 21D61
    • macOS (desktop)                        • macos                     • darwin-arm64   • macOS 14.3.1 23D60 darwin-arm64
    • Chrome (web)                           • chrome                    • web-javascript • Google Chrome 122.0.6261.129

[✓] Network resources
    • All expected network resources are available.

• No issues found!

I hope this helps. If you go the route of implementing your own logic (which should be relatively easy) and you find the problem please let us know maybe we can incorporate it into the permission_handler. I am going to close this issue now as all seems to work fine.

mvanbeusekom avatar Mar 19 '24 10:03 mvanbeusekom