gdelataillade / alarm

A Flutter plugin to easily manage alarms on iOS and Android
https://pub.dev/packages/alarm
MIT License
132 stars 86 forks source link

Make the notification dismissible #121

Closed JosipDomazetDev closed 7 months ago

JosipDomazetDev commented 11 months ago

Hello,

I'm unsure whether this is a potential bug or a feature request, but I've observed an issue after launching an alarm. The notification created during this process doesn't automatically disappear; instead, it remains indefinitely until the alarm is manually stopped (with await Alarm.stop(alarmID)).

The challenge arises when the user closes the app before stopping the alarm, as there's no guarantee that the alarm will be halted in time. Consequently, users may be left with a persistent notification that cannot be dismissed even when the app is closed -- this quite unpleasant.

With "dismiss" I refer to the users ability to swipe away or somehow remove the notification.

I've conducted tests on multiple Android devices, and the issue persists across all of them.

Thank you for looking into this matter.

Here is a screenshot of a zombie notification: Screenshot_2023-12-22-02-14-44-094_com mi android globallauncher

gdelataillade commented 10 months ago

Hi @JosipDomazetDev

The fact that the notification is not dismissible is part of Android's approach to ensure user awareness of ongoing processes that could affect the device's performance or battery life. If the notification stays here, it means the alarm service is still running. I'll find a way to stop it when necessary but I'm not sure how.

What kind of alarm do you use ? Is your loopAudio set to true or false ? You expect the notification to disappear when alarm stop ringing ?

JosipDomazetDev commented 9 months ago

Hey, this is my current config:

final alarmSettings = AlarmSettings(
    id: alarmID,
    dateTime: triggerAlarmDate,
    loopAudio: false,
    vibrate: doesVibrate,
    fadeDuration: preferredDuration.toDouble(),
    assetAudioPath: 'assets/sounds/reminder.wav',
    notificationTitle: 'Start your set!',
    notificationBody: '$seconds seconds have passed.',
    enableNotificationOnKill: false);

I feel like it's more natural if the notification disappears, at least after the user opens the app again.

gdelataillade commented 9 months ago

Hi @JosipDomazetDev

The notification will automatically disappear as soon as you call Alarm.stop. It is important to call this method when user open the app (when alarm rings) because it will dispose the alarm background tasks. This is what I recommend to fix your issue. What do you think ?