Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 of 2 tasks
deadman00069 opened this issue Aug 14, 2022 · 15 comments

Comments

@deadman00069
Copy link

deadman00069 commented Aug 14, 2022

🐛 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:

  • 📱 iOS
  • 🤖 Android
@marcsanny
Copy link

Any news on that?

@yarn-rp
Copy link

yarn-rp commented Aug 23, 2022

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"

@mockturtl
Copy link

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: 051828f), 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
Copy link

mockturtl commented Sep 8, 2022

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.
firebase/flutterfire#9486 EDIT: fix landed in firebase_messaging 13.0.1

@tmaihoff
Copy link

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.

@HuyDragun
Copy link

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

@Xanonymous-GitHub
Copy link

Xanonymous-GitHub commented Jan 5, 2023

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-.

@premathunga
Copy link

change compileSdkVersion and targetSdkVersion:
compileSdkVersion 33
targetSdkVersion 33

showing notification request dialog

@AliPunjabi
Copy link

AliPunjabi commented Feb 13, 2023

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

@Xanonymous-GitHub
Copy link

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.

@JARG85
Copy link

JARG85 commented Mar 21, 2023

@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.

@AbishekPerera
Copy link

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

@dubocr
Copy link

dubocr commented Jun 14, 2023

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"/>

@shoebsultan
Copy link

shoebsultan commented Jun 24, 2023

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

permission_handler: ^10.2.0

@mvanbeusekom
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests