Local notifications

177 views
Skip to first unread message

Sam Cromer

unread,
Aug 22, 2019, 5:16:14 PM8/22/19
to Flutter Dev
I’m messing with local notifications and am trying to create scheduled ones. I get no errors but the notifications never happen . What’s the best way to debug these? I’ve stepped thru all the code and nothing throws an error message

Rex Bloom

unread,
Aug 22, 2019, 5:19:19 PM8/22/19
to Sam Cromer, Flutter Dev
Sam,

Can you share some source code?

Rex

On Thu, Aug 22, 2019 at 4:16 PM Sam Cromer <s...@lightbridgeinc.com> wrote:
I’m messing with local notifications and am trying to create scheduled ones. I get no errors but the notifications never happen . What’s the best way to debug these? I’ve stepped thru all the code and nothing throws an error message

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/CAFmLuy6DVMs%2BOvkFRhOB1cLv8VtA4XZx925c4f5AMK%3DM8yN-wg%40mail.gmail.com.

Andy Greenshaw

unread,
Aug 22, 2019, 5:23:10 PM8/22/19
to Flutter Dev, Sam Cromer
Have you done all the required setup (in the Android and iOS projects)?
On 22 Aug 2019, 22:16 +0100, Sam Cromer <s...@lightbridgeinc.com>, wrote:
I’m messing with local notifications and am trying to create scheduled ones. I get no errors but the notifications never happen . What’s the best way to debug these? I’ve stepped thru all the code and nothing throws an error message

--

Sam Cromer

unread,
Aug 22, 2019, 6:41:56 PM8/22/19
to Andy Greenshaw, Flutter Dev
I believe so , I’m mirroring the flutter awesome app for medicine reminders . I’ll post it when I get home thanks for the help 

Sent from my iPhone

Sam Cromer

unread,
Aug 23, 2019, 10:37:28 AM8/23/19
to Andy Greenshaw, Flutter Dev

Here is the code. I had to fix sound and launcher_icon errors, at this point nothing throws an error but no notifications come thru so im assuming im missing something config wise but I have looked in the android manifest file and pub and have mirrored everything in the working demo.

 

SCHEDULE NOTIFICATION CODE

 

Future<void> scheduleNotification(Medicine medicine) async {

    var hour = int.parse(medicine.startTime[0] + medicine.startTime[1]);

    var ogValue = hour;

    var minute = int.parse(medicine.startTime[2] + medicine.startTime[3]);

 

    var androidPlatformChannelSpecifics = AndroidNotificationDetails(

      'repeatDailyAtTime channel id',

      'repeatDailyAtTime channel name',

      'repeatDailyAtTime description',

      importance: Importance.Max,

      sound: 'sound',

      ledColor: Color(0xFF3EB16F),

      ledOffMs: 1000,

      ledOnMs: 1000,

      enableLights: true,

    );

    var iOSPlatformChannelSpecifics = IOSNotificationDetails();

    var platformChannelSpecifics = NotificationDetails(

        androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);

 

    for (int i = 0; i < (24 / medicine.interval).floor(); i++) {

      if ((hour + (medicine.interval * i) > 23)) {

        hour = hour + (medicine.interval * i) - 24;

      } else {

        hour = hour + (medicine.interval * i);

      }

      await flutterLocalNotificationsPlugin.showDailyAtTime(

          int.parse(medicine.notificationIDs[i]),

          'Medication Reminder: ${medicine.medicineName}',

          medicine.medicineType.toString() != MedicineType.None.toString()

              ? 'It is time to take your ${medicine.medicineType.toLowerCase()}, according to schedule'

              : 'It is time to take your medicine, according to schedule',

          Time(hour, minute, 0),

          platformChannelSpecifics);

      hour = ogValue;

    }

    //await flutterLocalNotificationsPlugin.cancelAll();

  }

}

 

 

PUBSPEC Dependencies

 

dependencies:

  flutter:

    sdk: flutter

 

  # The following adds the Cupertino Icons font to your application.

  # Use with the CupertinoIcons class for iOS style icons.

  cupertino_icons: ^0.1.2

  rxdart: ^0.22.0

  provider: ^3.0.0+1

  shared_preferences: 0.5.2

  flutter_local_notifications:

  flare_flutter:

    git:

      ref: dev

      path: flare_flutter

 

dev_dependencies:

  flutter_test:

    sdk: flutter

 

  flutter_redux: ^0.5.2

  snaplist: ^0.1.3

  font_awesome_flutter: ^8.0.1

  http: ^0.12.0

  intl: ^0.15.7

  device_calendar: ^0.0.7

  dynamic_theme:

  eva_icons_flutter:

  flutter_speed_dial:

  sqflite:

  url_launcher: ^5.0.3

  swipedetector: ^1.2.0

  contacts_service: ^0.2.1

  agora_rtc_engine: 0.9.4

  permission_handler: ^3.0.0

  validators: ^2.0.0

  path_provider: ^1.1.0

  share_extend: ^1.0.9

  shimmer: ^1.0.0

  flutter_launcher_icons: "^0.7.2"

 

flutter_icons:

  android: "launcher_icon"

  ios: false

  image_path: "assets/logo/Mediminder_Logo.png"

 

 

ANDROID manifest

 

  <uses-permission android:name="android.permission.INTERNET"/>

    <uses-permission android:name="android.permission.READ_CALENDAR" />

    <uses-permission android:name="android.permission.WRITE_CALENDAR" />

    <uses-permission android:name="android.permission.READ_CONTACTS" />

    <uses-permission android:name="android.permission.WRITE_CONTACTS" />

    <uses-permission android:name="android.permission.VIBRATE" />

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

 

 

 

 

 

Sent from Mail for Windows 10

AndyTomG

unread,
Aug 23, 2019, 5:48:05 PM8/23/19
to Sam Cromer, Flutter Dev
Not at my computer, but when your app starts what does “var pendingNotificationRequests =
        await flutterLocalNotification” give you? Does it show the notifications you have scheduled?
Also, have you added
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED"></action>
    </intent-filter>
</receiver>

and 
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />

Cheers,
Andy

AndyTomG

unread,
Aug 23, 2019, 6:00:38 PM8/23/19
to Sam Cromer, Flutter Dev
Also assuming you’ve done a very basin notification for 15 secs from “now” to see if it fires. If yes, then I guess your time calculations are wrong, if no I guess it’s configuration/permissions (and check the get all notifications to check it’s been set).


Cheers,
Andy

On 23 Aug 2019, at 15:37, Sam Cromer <s...@lightbridgeinc.com> wrote:

Sam Cromer

unread,
Aug 26, 2019, 3:17:58 PM8/26/19
to AndyTomG, Flutter Dev

Thank you AndyTomG! That fixed it, I was missing the Android manifest receiver settings.

 

Im new to flutter and setting up notifications, do these notifications work when the app is NOT running as well?

 

I also need to set up push notifications for my app do you have a preference on what to use for those?

 

Thanks,

Sam

 

Sent from Mail for Windows 10

 

Andy Greenshaw

unread,
Aug 26, 2019, 3:27:52 PM8/26/19
to Sam Cromer, Flutter Dev
Yes, once set, local notifications still fire (happen) when the app is closed - but it’s up to the app to handle being launched (if user taps on it) from the notification (eg go to specific page).

Firebase Messaging for push notifications.

Cheers,
Andy
 

From: Sam Cromer <s...@lightbridgeinc.com>
Sent: Monday, August 26, 2019 8:17 pm
To: AndyTomG
Cc: Flutter Dev
Subject: RE: Local notifications
 

Sam Cromer

unread,
Aug 26, 2019, 3:30:49 PM8/26/19
to Andy Greenshaw, Flutter Dev
Thanks for the help! 

Sent from my iPhone

EthicCoders Apps

unread,
Aug 26, 2019, 4:41:42 PM8/26/19
to Sam Cromer, AndyTomG, Flutter Dev
I too used to use firebase push notifications (FCM) - its good until you would like to send images in the notification, which show up in the notification expanded view. In my experience, the below particular use case is still not handled by fcm flutter plugin. 
  • Auto Send Push Notification with Images when the app is terminated: So, when the app is closed (not running in the background) and we want to send an image-based push notification programmatically using backend like nodejs along with cloud functions, the image doesn't show up. ( fcm flutter plugin link, check receiving messages part - the message is lost)
I was not able to solve the above use case, that was the reason, I had to switch to OneSignal push notifications. I must admit the OneSignal flutter Plugin works like a charm when sending auto push image notifications (with backend nodejs and cloud functions).  Ex: Our Catholic News App integrated with OneSignal - Receives and displays auto push notifications of Latest News along with news article image. 

If image notifications is not your requirement, then fcm will suffice. 

NB: disclaimer not associated with OneSignal :) 


Reply all
Reply to author
Forward
Message has been deleted
0 new messages