flutter_local_notifications
flutter_local_notifications copied to clipboard
Schedule notifications not working in Android 14
Schedule notifications not working since I upgraded my phone to Android 14 using Samsung A53.
Permissions in AndroidManifest: USE_EXACT_ALARM SCHEDULE_EXACT_ALARM POST_NOTIFICATIONS
Expected: Schedule notifications must be received at exact time.
I have like 10 schedule notifications a day and I receive most of them at once or when opening the App. Never changed anything since Android 13 except adding the SCHEDULE_EXACT_ALARM.
Any idea what am missing?
Do you have added POST_NOTIFICATIONS permissions inside your AndroidManifest ? i remember got an issue and console ask me to add it.
Do you have added POST_NOTIFICATIONS permissions inside your AndroidManifest ? i remember got an issue and console ask me to add it.
Yes I already have POST_NOTIFICATIONS permission in AndroidManifest. The only work around solution I found so far is to disable "Battery Optimization" and all schedule notifications are received on exact time.
Hi, I also can confirm that the schedule notications are not working in Android 14 on my Google Pixel 4a 5G at the moment with both SCHEDULE_EXACT_ALARM e POST_NOTIFICATIONS permission enabled in AndroidManifest.
I'd also like to inform you that I've noticed that the scheduled notifications are working only when the app is compiled or is running in debug mode. As soon as I generate the apk file in release mode, the scheduled notifications stop showing on the screen.
I hope this information can help to understand the cause of the issue.
same problem here. any solution in sight?
Same issue on Galaxy A34 running Android 14. Either the notifications are late or not triggering until the app is opened. Even when excluded from sleep.
I have the same issue, notification not trigger on Android 14
The plugin doesn't have anything that's Android 14 specific and I've had Pixel 6 and 8 devices where the example app works as expected on them. If you're experiencing delays then this is outside the control of the plugin and devices that don't run the stock Android OS are susceptible to this issue due to battery optimisations as covered in https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications#scheduled-android-notifications. Please have a read of that section that I've linked. If you're seeing differences in OS versions then you'll need to see if the manufacturer introduced further changes.
@ZSHUser01 given what you've described, it would sound like you haven't followed the steps mentioned in https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications#release-build-configuration
@MaikuB Thank you for for the feedback. I'll try to refollow the steps described in the README as you suggested. Probably, I' ve missed something in my release build configuration.
Thank you again for the feedback
@MaikuB and @ZSHUser01 I had a similar problem.
Unhandled Exception: PlatformException(error, Missing type parameter., null, java.lang.RuntimeException: Missing type parameter. E/flutter (23073): at a7.a.d(SourceFile:27) E/flutter (23073): at a7.a.<init>(SourceFile:2) E/flutter (23073): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin$a.<init>(SourceFile:1) E/flutter (23073): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.loadScheduledNotifications(SourceFile:26) E/flutter (23073): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.removeNotificationFromCache(SourceFile:1) E/flutter (23073): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.cancelNotification(SourceFile:54) E/flutter (23073): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.cancel(SourceFile:23) E/flutter (23073): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(SourceFile:382) E/flutter (23073): at p8.k$a.a(SourceFile:18) E/flutter (23073): at g8.c.l(SourceFile:19) E/flutter (23073): at g8.c.m(SourceFile:41) E/flutter (23073): at g8.c.i(SourceFile:1) E/flutter (23073): at g8.b.run(SourceFile:1)
And this was cause by a missing the release configuration (proGuard). By just adding the proguard-rules.pro from the example everything works fine.
Same on Galaxy S22 android 14. No problem on iOS, android 9, android 10.
This is new for android 14:
If the app requires scheduling notifications with exact timings (aka exact alarms), there are two options since Android 14 brought about behavioural changes (see here for more details)
specify <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" /> and call the requestExactAlarmsPermission() exposed by the AndroidFlutterNotificationsPlugin class so that the user can grant the permission via the app or specify <uses-permission android:name="android.permission.USE_EXACT_ALARM" />. Users will not be prompted to grant permission, however as per the official Android documentation on the USE_EXACT_ALARM permission (refer to [here](https://developer.android.com/about/versions/14/changes/schedule-exact-alarms#calendar-alarm-clock) and [here](https://developer.android.com/reference/android/Manifest.permission#USE_EXACT_ALARM)), this requires the app to target Android 13 (API level 33) or higher and could be subject to approval and auditing by the app store(s) used to publish theapp
Might have to do with energy management settings indeed. I find my app back in 'deep snooze' while it started multiple times a day.
I need to do some more testing but adding the following parameter to the zonedSchedule notifications are shown at the right time at android 14.
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
As alternative I've found that adding the following permission also works (but might cause a Play Store rejection for what I've read. But I doubt they are so strict)
Note if you're targeting Android 13 or higher, specifying the permissions in manifest won't be an alternative but actually mandatory for your app. If you specify android.permission.SCHEDULE_EXACT_ALARM
then you need to ensure that your app also calls the requestExactAlarmsPermission()
method provided by the plugin as the user needs to decide if they want to grant your app permission. This is mentioned at https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications#androidmanifestxml-setup
@admincode1 you should check that you specified
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle
like @PeperMarkreel mentioned as that is what the plugin exposes to allow for notifications to trigger with exact timing even the phone has been doze/low-power idle mode. Certain Android OEMs may have stricter battery optimisations that is outside of the control the plugin and this is related to what is documented at https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications#scheduled-android-notifications. This is something all developers will need to bear in mind and isn't a bug with the plugin but due to customisations done that by Android OEMs to the version of Android OS they put on their devices
After adding "androidScheduleMode: AndroidScheduleMode.alarmClock" to zonedSchedule notifications, notifications are shown in the exact scheduled time. Thanks @PeperMarkreel & @MaikuB
Samsung seems to ignore setExact() and setExactAndAllowWhileIdle(), but using setAlarmClock() is working so far on my end - at least on Galaxy A34. So in .zonedSchedule() you can use:
androidScheduleMode: AndroidScheduleMode.alarmClock,
Documentation on "exact alarms": https://developer.android.com/develop/background-work/services/alarms/schedule#set-exact-alarm