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

Calling alarm stop does not make the notification disappear from the status bar. #215

Open synstin opened 5 months ago

synstin commented 5 months ago

Alarm plugin version 3.1.4

Describe the bug Is it correct behavior that calling Alarm.stopAll() makes the notification disappear from the status bar?

Sometimes calling stopAll() doesn't make the notification disappear from the status bar. So, after debugging, I found a few things.

final hasAlarm = Alarm.hasAlarm(); // false
final getAlarms = Alarm.getAlarms(); // size=0
final checkAlarm = await Alarm.checkAlarm(); // null
final isRinging = await Alarm.isRinging(1); // true

The isRinging variable appears to be true. However, all notifications have already ended. Is this a bug?

AlarmSettings(
          id: 1,
          dateTime: DateTime.now().add(Duration(seconds: 5)),
          assetAudioPath: 'assets/sound/test.mp3',
          loopAudio: false,
          vibrate: false,
          notificationTitle: 'test',
          notificationBody: "test",
          enableNotificationOnKill: false,
          androidFullScreenIntent: true,
)

The AlarmSettings currently in use.

**DeviceInfo This only happens on Android. Does not occur on IOS. On Android, stopAll() doesn't seem to stop notifications properly.

**Additional After further testing, stop(1) correctly removes notification 1. But stopAll() doesn't work.

gdelataillade commented 5 months ago

Hi @synstin,

Thanks for the details. It seems there is a difference between stopAll (which relies on persistent storage for alarm info) and isRinging (which checks if an audio player with a specific ID is ringing).

When isRinging returns true but getAlarms returns nothing, is your alarm actually playing audio?

Could you please test this scenario a few more times and share the results? More data will help us identify the issue.

I’ll look into this and keep you updated.

synstin commented 5 months ago

@gdelataillade The notification is not actually playing audio. My audio is a very short ding- sound, less than a second. I wait a long time and then debug and isRinging comes out as true.

Future<void> stopAndSet() async {
  await Alarm.stopAll();
  await Alarm.set(AlarmSettings(
          id: 1,
          dateTime: DateTime.now().add(Duration(seconds: 5)),
          assetAudioPath: 'assets/sound/test.mp3',
          loopAudio: false,
          vibrate: false,
          notificationTitle: 'test',
          notificationBody: "test",
          enableNotificationOnKill: false,
          androidFullScreenIntent: true,
  ));
}

void run() async {
  await stopAndSet();
  await stopAndSet();
  await stopAndSet();
  await stopAndSet();
  await stopAndSet();
  await stopAndSet();
  Alarm.stopAll();
}

This is the logic that simplified my business. It seems to happen when deleting/registering multiple alarms in a row.