I am trying to show a pop up for requesting notification permission. I have tried using permission_handler package but for notification and bluetooth, it will show no dialog. Is there any other way to show dialog to ask notification permission ?
-
I know it doesn't help but I'm having the same problem on Android 13. Have you found a solution?Tomasz Cz.– Tomasz Cz.2022-09-17 16:15:44 +00:00Commented Sep 17, 2022 at 16:15
-
Hi @TomaszCz. I haven't found any solution yet for my case and still looking for it until nowwahyu– wahyu2022-09-19 01:36:51 +00:00Commented Sep 19, 2022 at 1:36
-
1I just try the solution from @Abdelrahman Tareq today and it works but for pop up notification we should do it manuallywahyu– wahyu2022-09-19 01:57:37 +00:00Commented Sep 19, 2022 at 1:57
Add a comment
|
3 Answers
Using permission_handler package, the following code will pop up a dialog requesting the user for notification permission:
Future<void> requestNotificationPermissions() async {
final PermissionStatus status = await Permission.notification.request();
if (status.isGranted) {
// Notification permissions granted
} else if (status.isDenied) {
// Notification permissions denied
} else if (status.isPermanentlyDenied) {
// Notification permissions permanently denied, open app settings
await openAppSettings();
}
}
You may call the function inside the main function or anywhere you see fit.
1 Comment
Mohit Dixit
Thanks a lot after lib update to latest it working like charm.
You can use notification_permission
2 Comments
wahyu
Hi I just try it today and so far it works fine, thank you very much @Abdelrahman Tareq for your help
Abdelrahman Tareq
You're welcome my friend
I got the same issue that it didn't show the pop up. Here is my solution:
- iOS:
In Podfile, I change value from 0 into 1 for permissions that I need to use. For ex:
...
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
# YOUR CUSTOM TARGET CODE HERE.
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
## dart: PermissionGroup.calendar
'PERMISSION_EVENTS=0',
## dart: PermissionGroup.notification
'PERMISSION_NOTIFICATIONS=1',
## dart: PermissionGroup.bluetooth
'PERMISSION_BLUETOOTH=1',
]
end
end
end
- Android:
In android -> app -> build.gradle, I set 33 for targetSdkVersion. For ex:
...
android {
...
defaultConfig {
...
minSdkVersion 21 // flutter.minSdkVersion
targetSdkVersion 33 // flutter.targetSdkVersion
...
}
...
}
...
Hope this helps.