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

Scheduled Local Notifications are delayed/ don't show on Android 8.1 #160

Closed
alexandranb opened this issue Jan 22, 2019 · 22 comments
Closed

Comments

@alexandranb
Copy link

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

@MaikuB
Copy link
Owner

MaikuB commented Jan 22, 2019

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)?

@hdvsyu
Copy link

hdvsyu commented Jan 23, 2019

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

@MaikuB
Copy link
Owner

MaikuB commented Jan 23, 2019

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

@hdvsyu
Copy link

hdvsyu commented Jan 23, 2019

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

@MaikuB
Copy link
Owner

MaikuB commented Jan 23, 2019

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.

@alexandranb
Copy link
Author

Hi @MaikuB ,

Does recurring refer to repeating notifications or even scheduled notifications?

Thanks

@MaikuB
Copy link
Owner

MaikuB commented Jan 23, 2019

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?

@MaikuB
Copy link
Owner

MaikuB commented Jan 23, 2019

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

@florinion
Copy link

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

@MaikuB
Copy link
Owner

MaikuB commented Jan 26, 2019

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

@alexandranb
Copy link
Author

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!

@MaikuB
Copy link
Owner

MaikuB commented Jan 30, 2019

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

@MaikuB MaikuB mentioned this issue Jan 30, 2019
@MaikuB
Copy link
Owner

MaikuB commented Jan 30, 2019

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

@MaikuB MaikuB closed this as completed Jan 30, 2019
@WahibAbdul
Copy link

WahibAbdul commented Dec 16, 2019

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

@MaikuB
Copy link
Owner

MaikuB commented Dec 16, 2019

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

@WahibAbdul
Copy link

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,
);

}

@MaikuB
Copy link
Owner

MaikuB commented Dec 16, 2019

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

@MaikuB
Copy link
Owner

MaikuB commented Dec 16, 2019

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)

@MaikuB
Copy link
Owner

MaikuB commented Dec 16, 2019

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

@WahibAbdul
Copy link

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

@Bogr11
Copy link

Bogr11 commented Mar 26, 2020

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

@Aleksandar1204
Copy link

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

I'm having the same issue now,

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

7 participants