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

await Permission.notification.request() not showing dialog to grant notification permission on android api version 32 Tiramisu

Open deadman00069 opened this issue 3 years ago • 4 comments

🐛 Bug Report

Calling request() method on Permission.notification does not show system dialog and always returns PermissionStatus.denied on Android 13 (Emulator running API: 32 Tiramisu) and (Emulator running API: 33). I also run example project from and still not getting dialog

Expected behavior

Notification permission is requested.

Reproduction steps

Create Android Emulator with API 32 and 33, launch the example project, and request notification permission.

Configuration

Version: 10.0.0

Platform:

  • [ ] :iphone: iOS
  • [x] :robot: Android

deadman00069 avatar Aug 14 '22 07:08 deadman00069

Any news on that?

marcsanny avatar Aug 19 '22 13:08 marcsanny

As you probably may know, android permissions API has changed. Now you need to provide more info to the OS. The latest version of this package actually supports this just by adding some info to android config files:

  1. Make sure to have latest version of this plugin ( 10.0.0 works as expected)
  2. Add the following line in android/app/src/main/AndroidManifest.xml:
  <!-- Permissions options for the `notification` group -->
  <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
  1. In the file android/app/build.gradle, inside of android block, change compileSdkVersion and targetSdkVersion:
//...
android {
    compileSdkVersion 33
    //  ...
    defaultConfig {

        applicationId "your.app.id"
        minSdkVersion //your sdk min version
        targetSdkVersion 33
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }
   // ...
}

  1. In case you haven't support latest android versions, android 12 and 13 requires android:exported="true" property in activity just below android:name=".MainActivity"

yarn-rp avatar Aug 23 '22 01:08 yarn-rp

If someone has the notification permission prompt working, can you please post a screenshot, and flutter doctor?

Several PR's and comments indicate these changes should be sufficient to make the example app work (currently: 051828f0c5b572fde65ef3474af0de29407fe9aa), but they don't seem to help.

--- a/permission_handler/example/android/app/src/main/AndroidManifest.xml
+++ b/permission_handler/example/android/app/src/main/AndroidManifest.xml
@@ -7,6 +7,7 @@
     the internet.
     -->
     <uses-permission android:name="android.permission.INTERNET"/>
+    <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
 
     <!-- Permissions options for the `contacts` group -->
     <uses-permission android:name="android.permission.READ_CONTACTS"/>
diff --git a/permission_handler/example/pubspec.yaml b/permission_handler/example/pubspec.yaml
index f27debc..c356188 100644
--- a/permission_handler/example/pubspec.yaml
+++ b/permission_handler/example/pubspec.yaml
@@ -8,7 +8,7 @@ dependencies:
   baseflow_plugin_template:
     git:
       url: https://github.com/Baseflow/baseflow_plugin_template.git
-      ref: v2.1.0
+      ref: update-deprecated-button
   flutter:
     sdk: flutter

mockturtl avatar Sep 02 '22 19:09 mockturtl

SOLVED

My emulator was running an SDK that somehow displays as "Android API 33" but also "API 32."

After I fixed the SDK, the permission dialog works as expected.

Screenshot from 2022-09-06 15-09-09

Important note

Granting push permission via this plugin may result in a crash due to an unrelated bug in firebase_messaging. ~~https://github.com/firebase/flutterfire/pull/9486~~ EDIT: fix landed in firebase_messaging 13.0.1

mockturtl avatar Sep 08 '22 02:09 mockturtl

Still having this issue with permission_handler: ^10.2.0.

The dialog does not come up at all on android sdk 33 in release mode. Strange thing is, it works fine on debug mode.

It does not make a difference if I add the line to the Manifest or not.

tmaihoff avatar Nov 15 '22 18:11 tmaihoff

As you probably may know, android permissions API has changed. Now you need to provide more info to the OS. The latest version of this package actually supports this just by adding some info to android config files:

  1. Make sure to have latest version of this plugin ( 10.0.0 works as expected)
  2. Add the following line in android/app/src/main/AndroidManifest.xml:
  <!-- Permissions options for the `notification` group -->
  <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
  1. In the file android/app/build.gradle, inside of android block, change compileSdkVersion and targetSdkVersion:
//...
android {
    compileSdkVersion 33
    //  ...
    defaultConfig {

        applicationId "your.app.id"
        minSdkVersion //your sdk min version
        targetSdkVersion 33
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }
   // ...
}
  1. In case you haven't support latest android versions, android 12 and 13 requires android:exported="true" property in activity just below android:name=".MainActivity"

you saved me a tons of time, I try on my emulator for both android 13 & ios 16.1, all is showing notification request dialog

HuyDragun avatar Nov 23 '22 09:11 HuyDragun

Having this issue with permission_handler: ^10.2.0. My compileSDK is 33 and the dialog not shown in both dev mode and release mode.

await Permission.storage.request().isGranted // Not show anything
<!--  These lines added -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

And I found that this problem may caused by android API 33+. I can see the dialog when I build on API 32-.

Xanonymous-GitHub avatar Jan 05 '23 21:01 Xanonymous-GitHub

change compileSdkVersion and targetSdkVersion: compileSdkVersion 33 targetSdkVersion 33

showing notification request dialog

premathunga avatar Jan 13 '23 09:01 premathunga

I had applied all above configurations but still not getting the dialogue box for permissions. my compileSdkVersion 33 targetSdkVersion 33 added this tag in androidmanifest file: added android exported true permission handler: ^5.0.1 this is my code:

Future<void> getpermission() async {
  final androidInfo = await DeviceInfoPlugin().androidInfo;
  Map<Permission, PermissionStatus> statusess;

  if (androidInfo.version.sdkInt >= 33) {
    statusess = await [Permission.notification].request();
    print('$statusess');
  }
}

I am getting permission status un determined on print

AliPunjabi avatar Feb 13 '23 09:02 AliPunjabi

Seems this is caused by the new introduced Android API level 33 storage permission policy: Granular media permissions.

That means the READ_EXTERNAL_STORAGE can not be directly requested when api version >= 33. We should request one of READ_MEDIA_IMAGES, READ_MEDIA_VIDEO, and READ_MEDIA_AUDIO for accessing the app-scoped storage.

In this case, since the permission_handler: 10.2.0 (maybe) not implement this change yet, we should request the following permissions by ourselves:

-  Permission.storage,
+  Permission.videos, // READ_MEDIA_IMAGES & READ_MEDIA_VIDEO
+  Permission.audio, // READ_MEDIA_AUDIO

And in the AndroidManifest.xml, do this change:

-    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
-    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
+    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
+    <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
+        android:maxSdkVersion="32" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
+        android:maxSdkVersion="29" />

When one of these permissions is granted by user, the App seems ok to access its storage.

Xanonymous-GitHub avatar Feb 15 '23 22:02 Xanonymous-GitHub

@Xanonymous-GitHub Very thanks!!! the solution is add the new permissions: image And request in the function of library:

image

pd: i develop from react-native but that solution fix my error.

JARG85 avatar Mar 21 '23 04:03 JARG85

Actually, I am facing the same problem. The dependency seems to be working correctly, but the permission dialog does not appear in debug mode or any emulated environment, only on a real phone.

In my case, I built an APK and tried it on my Samsung phone. The app is showing the notification permission dialog to ask for permission.

Here are the relevant sections from my manifest:

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

And here are the dependencies listed in my pubspec.yaml file:

firebase_core: ^2.8.0
firebase_messaging: ^14.3.0
permission_handler: ^10.2.0

AbishekPerera avatar Jun 02 '23 10:06 AbishekPerera

Some package limits READ_EXTERNAL_STORAGE permission until sdk 29 only, to make sure permission are set in manifest for sdk 30,31 and 32, you could try :

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" tools:replace="android:maxSdkVersion" android:maxSdkVersion="32"/>

dubocr avatar Jun 14 '23 09:06 dubocr

@AbishekPerera thank you so much! changing the version of permission_handler which is given below worked for me

permission_handler: ^10.2.0

shoebsultan avatar Jun 24 '23 14:06 shoebsultan

I have tested the behaviour in the initial post (regarding the "notification" permission) on my Pixel 7a (in both release and debug mode) and the permission seems to work fine. Below are two screenshots, one showing the dialog, second showing the granted permissions after pressing allow:

Screenshot_20230725-091320 Screenshot_20230725-091326

I have used the example application to test (without any changes).

Tested with permission_handler version: 10.4.3

Details of my Flutter environment are:

flutter doctor -v
[✓] Flutter (Channel stable, 3.10.5, on macOS 13.4.1 22F770820d darwin-arm64, locale en-NL)
    • Flutter version 3.10.5 on channel stable at /Users/maurits/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 796c8ef792 (6 weeks ago), 2023-06-13 15:51:02 -0700
    • Engine revision 45f6e00911
    • Dart version 3.0.5
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/maurits/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.11.3

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

[✓] Android Studio (version 2022.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.6+0-17.0.6b802.4-9586694)

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

[✓] Connected device (3 available)
    • Pixel 7a (mobile) • 31071JEHN18081 • android-arm64  • Android 13 (API 33)
    • macOS (desktop)   • macos          • darwin-arm64   • macOS 13.4.1 22F770820d darwin-arm64
    • Chrome (web)      • chrome         • web-javascript • Google Chrome 114.0.5735.248

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

• No issues found!

Since the POST_NOTIFICATIONS permission seem to work fine, I am going to close this issue. If you do encounter an issue with the notification permission, please create a new issue and fill out the issue template as complete as possible.

mvanbeusekom avatar Jul 25 '23 07:07 mvanbeusekom