Baseflow / flutter-permission-handler

Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.
https://baseflow.com
MIT License
2.04k stars 850 forks source link

[Bug]: Android 14 not show dialog to require the permissions. #1232

Closed toknT closed 11 months ago

toknT commented 11 months ago

Please check the following before submitting a new issue.

Please select affected platform(s)

Steps to reproduce

In my app , it need to download pdf files to download folder, and I do it just like this issue: https://github.com/Baseflow/flutter-permission-handler/issues/955 .

Expected results

require the user permission

Actual results

do no thing and this error in console

D/permissions_handler( 6517): No permissions found in manifest for: []22

Code sample

_checkStoragePermission() async {
  PermissionStatus status;
  if (Platform.isAndroid) {
    final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
    final AndroidDeviceInfo info = await deviceInfoPlugin.androidInfo;
    if ((info.version.sdkInt) >= 33) {
      status = await Permission.manageExternalStorage.request();
    } else {
      status = await Permission.storage.request();
    }
  } else {
    status = await Permission.storage.request();
  }

  switch (status) {
    case PermissionStatus.denied:
      return false;
    case PermissionStatus.granted:
      return true;
    case PermissionStatus.restricted:
      return false;
    case PermissionStatus.limited:
      return true;
    case PermissionStatus.permanentlyDenied:
      return false;
  }
}

Screenshots or video

No response

Version

11.0.1

Flutter Doctor output

[√] Flutter (Channel stable, 3.13.9, on Microsoft Windows [Version 10.0.22621.2715], locale ja-JP)
    • Flutter version 3.13.9 on channel stable at C:\src\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d211f42860 (3 weeks ago), 2023-10-25 13:42:25 -0700
    • Engine revision 0545f8705d
    • Dart version 3.1.5
    • DevTools version 2.25.0

[√] 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:\Users\tokns\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[X] Visual Studio - develop Windows apps
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2021.3)
    • Android Studio at C:\Program Files\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.13+0-b1751.21-8125866)

[√] VS Code (version 1.84.2)
    • VS Code at C:\Users\tokns\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.76.0

[√] Connected device (3 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 14 (API 34) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.22621.2715]
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 119.0.2151.58
toknT commented 11 months ago

I forget to change the xml and on Andorid 14 it should usePermission.videos.request, sorry.

    <!-- Permissions options for the `storage` group -->
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
    if (info.version.sdkInt >= 33) {
      // android 13+
      status = await Permission.videos.request();
    } else if (info.version.sdkInt >= 30) {
      // android 11+ `storage.request()` still work on 11
      // status = await Permission.manageExternalStorage.request(); // full screen
      status = await Permission.storage.request();  // dialog
    } else {
      status = await Permission.storage.request();
    }
Marcos-Michel commented 5 months ago

No meu ele não aponta erro, simplesmente não exibe o dialogo para solicitar permissão. Mesmo realizando todas as alterações indicadas na pub dev do pacote. Android 14.

Mashi-91 commented 4 months ago

Same For me Not Showing any dialog either.

toknT commented 4 months ago

@Mashi-91 check you AndroidManifest.xml ,use Permission.videos.request() on android 13 or 13+, and restart the emulator not reload.

    if (info.version.sdkInt >= 33) {
      // android 13+
      status = await Permission.videos.request();
    } else if (info.version.sdkInt >= 30) {
      // android 11+ `storage.request()` still work on 11
      // status = await Permission.manageExternalStorage.request(); // full screen
      status = await Permission.storage.request();  // dialog
    } else {
      status = await Permission.storage.request();
    }
brunos0 commented 4 months ago

Same error here. I'm using a real device with android 14 and when permission is denied, when i try to ask user to give me permission the dialog dosen't appears....

Im trying to use Location, to use bluetooth scan method and find another near devices:

  void _checkPermissions() async {
    var status = await Permission.locationWhenInUse.status;

    if (status == PermissionStatus.granted) {
      showSnackbar('Permissão concedida.');
    } else if (status == PermissionStatus.permanentlyDenied) {
      // tratar aqui
      showSnackbar('Permissão negada permanentemente');
    } else if (status == PermissionStatus.denied) {
      final curContext = context;
      if (curContext.mounted) {
        await showDialog(
          context: curContext,
          builder: (ctx) => AlertDialog(
            title: const Text('Permissão não concedida'),
            content: const Text(
                '''Para sua comodidade, conceda a permissão para o uso da '''
                '''localização para 'sempre permitir durante o uso' do '''
                '''aplicativo Aferineu.'''),
            actions: [
              TextButton(
                onPressed: () {
                  Navigator.of(context).pop();
                },
                child: const Text('Fechar'),
              ),
            ],
          ),
        );
      }
      await Permission.locationWhenInUse.request();  // works until android 11
      //await Permission.location.request();

      //dosen't works too..
      /*
       bool isShown =
          await Permission.locationWhenInUse.shouldShowRequestRationale;
      */

      //requisitar aqui
      var status = await Permission.locationWhenInUse.status;
      if (status != PermissionStatus.granted) {
        showSnackbar('Permissão não concedida');
      } else {
        showSnackbar('Permissão concedida.');
      }
    } else {
      showSnackbar('Erro ao checar permissão.');
    }
  }

Manifest permissions:

    <uses-permission android:name="android.permission.INTERNET" />

    <!-- New Bluetooth permissions in Android 12
    https://developer.android.com/about/versions/12/features/bluetooth-permissions -->
    <!--Before Android 12 (but still needed location, even if not requested)-->
    <!-- uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" android:maxSdkVersion="30" / -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30"/>
    <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30"/>
    <!-- uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" / -->

    <!--From Android 12-->
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

    <!-- Since Bluetooth classis is a basic requirement for our app -->
    <uses-feature android:name="android.hardware.bluetooth" android:required="true" />

    <!-- Adding Bluetooth BLE for future new devices implementions -->
    <uses-feature android:name="android.hardware.bluetooth_le" android:required="true" />

is there some way to ask user again if the previous status are denied on android 12 and 14?

Kind Regards.