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

Basic notification flutterLocalNotificationsPlugin.show is not working #2282

Open
emadyounan opened this issue Mar 27, 2024 · 0 comments
Open

Comments

@emadyounan
Copy link

Dear all,

I'm using android_alarm_manager_plus 4.0.1 with flutter_local_notification. I'm trying to show an alarm notification at a specific time that the user will select, but my emulator not showing the notification I don't know what I'm missing Can anyone help me, please??

my alarm class:

class AlarmManagerSerive {
  Future<void> init() async {
    await AndroidAlarmManager.initialize();
  }

  static DateTime parseDateString(String dateString) {
    DateFormat format = DateFormat('MMM dd, yyyy');
    return format.parse(dateString);
  }

  void setAlarm() async {
    try {
      Map<String, dynamic> notificationDetails =
          Storage().box.read("notification_details");
      int helloAlarmID = notificationDetails['id'];
      log(notificationDetails['name']);
      var parsedDate = parseDateString(notificationDetails['reminderdate']);
      int hour = int.parse(notificationDetails['remindertime'].split(':')[0]);
      int min = int.parse(notificationDetails['remindertime'].split(':')[1]);
      String type = notificationDetails['type'];
      if (Platform.isAndroid) {
        if (type == "Once") {
          await AndroidAlarmManager.oneShotAt(
            DateTime(
              parsedDate.year,
              parsedDate.month,
              parsedDate.day,
              hour,
              min,
            ),
            helloAlarmID,
            printHello,
            exact: true,
            wakeup: true,
            allowWhileIdle: true,
            alarmClock: true,
            params: notificationDetails,
          );
        } else {
          await AndroidAlarmManager.periodic(
            const Duration(days: 1),
            helloAlarmID,
            printHello,
            startAt: DateTime(
              parsedDate.year,
              parsedDate.month,
              parsedDate.day,
              hour,
              min,
            ),
            exact: true,
            wakeup: true,
            allowWhileIdle: true,
            params: notificationDetails,
          );
        }
      }
    } catch (e) {
      log(e.toString());
    }
  }

  @pragma('vm:entry-point')
  static void printHello(id, notificationDetails) async {
    try {
      final DateTime now = DateTime.now();
      final int isolateId = Isolate.current.hashCode;
      // ignore: unnecessary_brace_in_string_interps, avoid_print
      print("[$now] Hello, world! isolate=${isolateId}");

      await LocalNotificationServices.showBasicNotification(
        notificationDetails?['id'],
        notificationDetails?['name'],
        notificationDetails?['describtion'],
      );
      log(notificationDetails['name']);
      performDatabaseUpdate(notificationDetails['id']);
      LocalNotificationServices.cancelNotification(notificationDetails['id']);
      AndroidAlarmManager.cancel(notificationDetails['id']);
    } catch (e) {
      log(e.toString());
    }
    log("notific");
  }

it should work as I'm getting my log correct

D/CompatibilityChangeReporter(31550): Compat change id reported: 194532703; UID 10191; state: ENABLED
D/CompatibilityChangeReporter(31550): Compat change id reported: 253665015; UID 10191; state: DISABLED
I/flutter (31550): [2024-03-27 22:28:00.142080] Hello, world! isolate=1012637609
[log] Once 1
[GETX] Instance "ReminderController" has been created
[GETX] Instance "ReminderController" has been initialized
[log] notific
[log] Reminder updated successfully
[log] Database Updated

and my manifest file

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />

    <service android:name="dev.fluttercommunity.plus.androidalarmmanager.AlarmService" android:permission="android.permission.BIND_JOB_SERVICE" android:exported="false"/>
    <receiver android:name="dev.fluttercommunity.plus.androidalarmmanager.AlarmBroadcastReceiver" android:exported="false"/>
    <receiver android:name="dev.fluttercommunity.plus.androidalarmmanager.RebootBroadcastReceiver" android:enabled="false" android:exported="false">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>

    <receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
    <receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
            <action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
        </intent-filter>
    </receiver>

My Basic notification

  static Future<void> showBasicNotification(
      int id, String title, String body) async {
    NotificationDetails details = NotificationDetails(
      android: AndroidNotificationDetails(
        id.toString(),
        title,
        channelDescription: body,
        importance: Importance.max,
        priority: Priority.high,
        playSound: true,
        enableVibration: true,
      ),
    );
    await flutterLocalNotificationsPlugin.show(
      id,
      title,
      body,
      details,
    );
  }

flutter doctor

[√] Flutter (Channel stable, 3.19.3, on Microsoft Windows [Version 10.0.19045.4170], locale en-US)
    • Flutter version 3.19.3 on channel stable at C:\Users\emady\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ba39319843 (3 weeks ago), 2024-03-07 15:22:21 -0600
    • Engine revision 2e4ba9c6fb
    • Dart version 3.3.1
    • DevTools version 2.31.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\emady\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.8.3)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.8.34330.188
    • Windows 10 SDK version 10.0.18362.0

[√] Android Studio (version 2023.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)

[√] VS Code (version 1.87.2)
    • VS Code at C:\Users\emady\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.84.0

[√] Connected device (4 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 14 (API 34) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.19045.4170]
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 123.0.6312.59
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 122.0.2365.92

[√] Network resources
    • All expected network resources are available.

• No issues found!
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

1 participant