Flutter_local_notifications: Scheduled Local Notifications are delayed/ don't show on Android 8.1

Created on 22 Jan 2019  Â·  21Comments  Â·  Source: MaikuB/flutter_local_notifications

Hi,

I have installed the local notifications plugin and set it up according to the instructions and they work as they should on lower android versions as it should.

However, on Android 8.1.0, the notifications are either delayed really badly or they don't show up at all.
I have registered the BroadcastReceiver class in AndroidManifest.xml, but still there is this problem.
I am scheduling multiple notifications and they are all having different ID's as I saw in a different issue that this is a problem.

Please advise.
Thank you

[√] Flutter (Channel beta, v1.0.0, on Microsoft Windows [Version 6.3.9600], locale en-US)
• Flutter version 1.0.0
• Framework revision 5391447fae (8 weeks ago), 2018-11-29 19:41:26 -0800
• Engine revision 7375a0f414
• Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)
• Platform android-28, build-tools 28.0.3
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
• All Android licenses accepted.

[√] Android Studio (version 3.2)
• Flutter plugin version 31.3.1
• Dart plugin version 181.5656
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[√] VS Code, 32-bit edition (version 1.29.1)
• Flutter extension version 2.21.1

Most helpful comment

Thanks for the feedback. I'll get that merged in and released soon

All 21 comments

What happens if you clone the repository and run the sample app on Android 8.1.0 (you can make adjustments to the date and time to see as part of testing)?

I have the same issue too.
I download this repository and run example after only change the time, it still occurs notification delay.
My android version is 8.0.0

@hdvsyu I understand you have the same issue but sorry I'm having trouble with understanding the rest of what you wrote

@MaikuB Sorry, my English is very poor...What I want to say is:
I also encountered the same problem.
I have cloned the repository and run the sample app on Android 8.0.0.
Then I adjusted the time, but the notifications were still delayed.

Got it. Yes I believe both of your issues related to what I've documented in the README

IMPORTANT: Recurring notifications on Android use the Alarm Manager API. This is standard practice but does mean the delivery of the notifications/alarms are inexact and this is documented Android behaviour as per the previous link.

Hi @MaikuB ,

Does recurring refer to repeating notifications or even scheduled notifications?

Thanks

Apologies you're right that was just for recurring notifications but did you get to check the sample app on the same device to see how it works?

Forgot to also ask, what device(s) are you seeing this happen on and does it also occur in an emulator?

Hi,

I am also experiencing the same issue with the plugin. I am trying to schedule multiple notifications and they are coming late on android 8.0 or higher. I tested my app on an emulator.
I also tried the sample app. It works fine for one or two notifications but if i schedule more than two they are coming late.
To test the sample app i scheduled 12 notifications to run every 5 minutes:

int minutesIncrement = 5;
var dateTimeNow = DateTime.now().toLocal();

    for(int i=1;i<=12;i++){
      var scheduledNotificationDateTime = dateTimeNow.add(new Duration(minutes: minutesIncrement));
      await flutterLocalNotificationsPlugin.schedule(
          i,
          'scheduled title $i',
          'scheduled: $scheduledNotificationDateTime',
          scheduledNotificationDateTime,
          platformChannelSpecifics);
      minutesIncrement= minutesIncrement+5;
    }

For this example, some were on time, some were late. The ones that were late came all at once along with one that was on time. For example the ones that were scheduled to appear at 14:00 and 14:05 came at the same time with the one at 14:10.

Thank you

Was re-reading again on the Alarm Manager API and yes actually the inexact delivery will affect one-off scheduled notifications as well and not really specific to Android 8. I've made some changes that I believe will fix the issue. If you could test it out by referencing the dev branch via git package notation and let me know if that solves the issue then that would be great

Hi,

I tested with the dev branch you gave and all is good now. The notifications are showing on time with no delay at all. Thank you very much!

Thanks for the feedback. I'll get that merged in and released soon

This should be in the new release now so will close this issue

@MaikuB facing this issue on Android 9. Working fine when showing notification with show() but not receiving notification when scheduling them. Scheduled notifications code is working fine on iOS.

Please provide a sample that reproduces the problem. If it's to do with notifications been delayed, then there's a note about this in the readme. If you're only scheduling individual notifications as opposed to recurring ones, an option had been added in the more recent versions of the plugin that you'll need to toggle on. See https://pub.dev/documentation/flutter_local_notifications/latest/flutter_local_notifications/FlutterLocalNotificationsPlugin/schedule.html

Notifications are not delayed, they are simply not showing up. They are of based random date and time so i can't use recurring option. This is the setup and scheduling code:

FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
    new FlutterLocalNotificationsPlugin();
var initializationSettingsAndroid =
    new AndroidInitializationSettings('ic_notification');
var initializationSettingsIOS = IOSInitializationSettings(
    onDidReceiveLocalNotification: onDidReceiveLocalNotification);
var initializationSettings = InitializationSettings(
    initializationSettingsAndroid, initializationSettingsIOS);
flutterLocalNotificationsPlugin.initialize(initializationSettings,
    onSelectNotification: onSelectNotification);


final androidPlatformChannelSpecifics = AndroidNotificationDetails(
  Config.NOTIFICATION_CHANNEL_ID,
  Config.NOTIFICATION_CHANNEL_NAME,
  Config.NOTIFICATION_CHANNEL_DESCRIPTION,
  importance: Importance.Max,
  priority: Priority.High,
  ticker: 'ticker',      
);
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
_platformChannelSpecifics = NotificationDetails(
    androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);

void schedule(
  String title,
  String message,
  DateTime dateTime, {
  int id,
  String payload,
}) async {
  await _flutterLocalNotificationsPlugin.schedule(
  id ?? DateTime.now().millisecond,
  title,
  message,
  dateTime,
  _platformChannelSpecifics,
  androidAllowWhileIdle: true,
);

}

Make sure to have configured your AndroidManifest.xml file as covered in the readme. This has been the common thing I've seen missed when issues have been raised that they don't work on Android

Also note that when I mentioned a sample app to reproduce the problem, I was referring to a complete app (this could be a link to a repo on GitHub)

There's also a bug in your code in how use the millisecond component as the id

I was missing Android manifest configuration. Thank you very much for your quick response.

Hello,

I'm facing the same issue on Android 9.0, phone OnePlus5T.
Notifications stop being received when the app is terminated.
For Android 6.0, phone Xiaomi Redmi note 4 everything works fine.
For Android 9.0, phone Samsung Galaxy M30s works fine as well.
I cloned your repo, opened example app as flutter project
and added "androidAllowWhileIdle: true" as a parameter to schedule method.
Is it something I am missing?
If you need more information on this - just tell me.

UPDATE

It starts working for me in terminated app also only if I turn on 4g traffic.
Otherwise (even with enabled wi-fi connection) notifications are shown only when app is open or in bg.

Apparently it looks like adaptive battery was causing the issues. After switching it off and on notifications do arrive event if app is terminated. So basically the issue is resolved. Will leave my comment here though, mb would help someone.

Best regards, Borys

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yanivshaked picture yanivshaked  Â·  5Comments

rafaelsetragni picture rafaelsetragni  Â·  5Comments

hsalazarl picture hsalazarl  Â·  6Comments

seanmavley picture seanmavley  Â·  5Comments

prolongservices picture prolongservices  Â·  4Comments