Flutter_local_notifications: Scheduled notifications dont work

Created on 31 Aug 2018  路  17Comments  路  Source: MaikuB/flutter_local_notifications

Hi,

I am sure that I am missing something but I don't know why. I have tried scheduling notifications through example app and those are working just fine. But when I schedule those in my own app (following the documentation), it schedules the alarms in AlarmManager (Android v8.1.0) but I am not getting the notifications on the phone.

RTC_WAKEUP #1: Alarm{deed396 type 0 when 1535946600875 com.example.timetablenotifier}  >tag=*walarm*:com.example.timetablenotifier/com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver
 type=0 whenElapsed=+1h0m30s608ms when=2018-09-03 08:50:00
 window=+5d6h0m0s0ms repeatInterval=604800000 count=0 flags=0x0
 operation=PendingIntent{f2bfb17: PendingIntentRecord{7051b04 com.example.timetablenotifier broadcastIntent}}

Here is how I am scheduling the notifications:

var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
      'channel id', 'channel name', 'channel description',
      importance: Importance.Max,
      priority: Priority.High,
      icon: 'ic_launcher',
      onlyAlertOnce: true);
var iOSPlatformChannelSpecifics = new IOSNotificationDetails();
var platformChannelSpecifics = new NotificationDetails(
      androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.showWeeklyAtDayAndTime(
          0, notificationTitle, notificationBody, new Day(dayI + 2),
          new Time(startTime - 1, 50, 0), platformChannelSpecifics);

Any help would be appreciated.

Thanks

Most helpful comment

You need to give each notification a unique ID. Just noticed it's your code always uses zero. The timing of the notifications will not be exact, this is documented in the readme already due to how the Android alarm manager works for repeating alarms

All 17 comments

Double check what you've done and compare with the readme, particularly around the Android integration section

Thank you for the response. I have double checked everything and I have also went through the Android Integration section once again and my manifest have everything necessary added there. One thing that is bugging me is that it is adding alarms but notifications are not being showed.

As suggested, I have this in my manifest:

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.VIBRATE" />
...
        <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
        <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"></action>
            </intent-filter>
        </receiver>

Here is scheduled alarm:

RTC_WAKEUP #3: Alarm{cb3a906 type 0 when 1535943000172 com.example.timetablenotifier} tag=*walarm*:com.example.timetablenotifier/com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver
 type=0 whenElapsed=+35s51ms when=2018-09-03 07:50:00
 window=+5d6h0m0s0ms repeatInterval=604800000 count=0 flags=0x0
 operation=PendingIntent{6a2fbc7: PendingIntentRecord{f0605f4 com.example.timetablenotifier broadcastIntent}}

But it doesn't show up for some reason.

Afraid I don't know. Have you tried the same code with the day and time hardcoded in the example app? The other thing was the Day class was intended to used as enumeration for the days of the week. I don't know what the end values you're passing into the Day constructor and if they're within range (1-7). Though that does raise a point that I probably should've made it so that the constructor isn't visible

I am using Day constructor because I have 0th-indexed days in my JSON. I think I have managed to narrow down the issue.

It seems like if I schedule multiple (_showWeeklyAtDayAndTime) notifications at different times, only one that was scheduled last works. Is this the intended behavior or there is some issue? Can you please check if you can replicate this issue?

Thanks

I have managed to reproduce the same issue (on Android 8.1.0 API 27) in examples app.

                        await _showWeeklyAtDayAndTime();
                        await _showWeeklyAtDayAndTime2();
  Future _showWeeklyAtDayAndTime() async {
    var time = new Time(10, 0, 0);
    var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
        'show weekly channel id',
        'show weekly channel name',
        'show weekly description');
    var iOSPlatformChannelSpecifics = new IOSNotificationDetails();
    var platformChannelSpecifics = new NotificationDetails(
        androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
    await flutterLocalNotificationsPlugin.showWeeklyAtDayAndTime(
        0,
        'show weekly title',
        'Weekly notification shown on Monday at approximately ${_toTwoDigitString(time.hour)}:${_toTwoDigitString(time.minute)}:${_toTwoDigitString(time.second)}',
        Day.Monday,
        time,
        platformChannelSpecifics);
  }

  Future _showWeeklyAtDayAndTime2() async {
    var time = new Time(10, 5, 0);
    var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
        'show weekly channel id',
        'show weekly channel name',
        'show weekly description');
    var iOSPlatformChannelSpecifics = new IOSNotificationDetails();
    var platformChannelSpecifics = new NotificationDetails(
        androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
    await flutterLocalNotificationsPlugin.showWeeklyAtDayAndTime(
        0,
        'show weekly title',
        'Weekly notification shown on Monday at approximately ${_toTwoDigitString(time.hour)}:${_toTwoDigitString(time.minute)}:${_toTwoDigitString(time.second)}',
        Day.Monday,
        time,
        platformChannelSpecifics);
  }

I only get a notification at 10:05 and not at 10:00.

You need to give each notification a unique ID. Just noticed it's your code always uses zero. The timing of the notifications will not be exact, this is documented in the readme already due to how the Android alarm manager works for repeating alarms

Thank you so much Michael. I am too dumb using the same notification ID. I am actually moving a native app to flutter and in native app I didn't have to schedule multiple notifications at once so I never had this issue and I know about AlarmManager and its scheduling :)

Closing this issue.

No worries :)

Hi,

I have the same problem, and I have different unique ID's for my scheduled notifications. However they are delayed or not received at all when the app is terminated. This is happening specifically for Android 8.1.0, and on other versions of Android works as it should.

I am kindly asking for your advice.

Thank you

Hi,

I have the same problem, Please Help. In android 8.1.1

hey, the issue is somewhat similar, notifications get added to the pending list but are never displayed

I've not seen any reported bugs on this so any problems is likely due to not having done the appropriate configuration so will be up to developers to ensure they have configured everything

Thanks a lot for the response, but the configuration and setup seems to be complete and the instant notifications are working well, it鈥檚 just the scheduled notifications that don鈥檛 show up

That instant notifications appear doesn't say much and I get a lot of reports that setup is complete to find that it actually haven't. Based on your response, doesn't look like you are certain on this since you said "seems".

There is an example app in this repository that is fully configured. Can you reproduce the problem in example app? The other thing is if you are sure everything is configured, are you able to provide a minimal sample app that reproduces the problem?

sure i will try to do so if possible, will revisit all my configurations once and compare them with the example app, thank you

i am facing the same error. I can show notifications using the .show method but schedule method just won't work. I shows up in the pending notifications and the app doesn't show any error whatsoever on button press. I think it might have something to do with AndroidManifest file so could I wanted to ask that are there any changes we have to make in AndroidManifest file for scheduled notification to work

Thanks

@rishijohri read the readme

Was this page helpful?
0 / 5 - 0 ratings

Related issues

prolongservices picture prolongservices  路  4Comments

dyhwang picture dyhwang  路  5Comments

yanivshaked picture yanivshaked  路  5Comments

salah-rashad picture salah-rashad  路  3Comments

jaripekkala picture jaripekkala  路  5Comments