Notification kill disable
Closed this issue · 4 comments
How to disable notification clear on android
The notification is not cleared when the alarm rings on the MI device. But on Samsung devices, even when the alarm is ringing, the notification gets cleared.
this is our code
void ringNow(){
Alarm.set(alarmSettings: buildRingNow()).then((res) async {
if (res) {
DateTime currentTime=DateTime.now();
Alarms(
name: 'Ring Now',
chimes:1,
delay: 0,
hours: currentTime.hour.toString(),
light: true,
minutes: currentTime.minute.toString(),
sound: 9,
repeat: [0],
active: true,
meridian: currentTime.hour > 12 ? 'PM':'AM',
alarmId: alarmId,
);
}
});
}
AlarmSettings buildRingNow() {
alarmId = DateTime.now().millisecondsSinceEpoch % 10000 + 1;
DateTime originalDateTime = DateTime.now();
DateTime selectedDateTime = DateTime(originalDateTime.year, originalDateTime.month, originalDateTime.day, originalDateTime.hour, originalDateTime.minute,originalDateTime.second);
final alarmSettings = AlarmSettings(
id: alarmId,
dateTime: selectedDateTime,
loopAudio: true,
vibrate: true,
// volume: 0.04,
assetAudioPath: "assets/animation/marimba.mp3",
warningNotificationOnKill: Platform.isIOS,
androidFullScreenIntent: true,
notificationSettings: const NotificationSettings(
title: 'Therapon',
body: 'Ring Now',
stopButton: 'Stop Ring',
icon: 'notification_icon',
),
);
return alarmSettings;
}
Hi @rahulinfibrain,
Unfortunately, I don’t have a Samsung device to test this, and notification behavior can vary significantly between Android manufacturers. Could you try modifying the .setAutoCancel(true)
to .setAutoCancel(false)
in package's android/src/main/kotlin/com/gdelataillade/alarm/services/NotificationService.kt
and let me know if this resolves the issue?
Thanks, and I look forward to your update!
ok, I will try it and inform you
Not Working
Android api level 32 above all versions, same issue
I did some testing on a Google Pixel 8a running Android 15, and I observed that even with .setAutoCancel(false)
and .setOngoing(true)
, the notification tied to a foreground service was still dismissible by swiping.
This aligns with changes introduced in Android 14, which updated the behavior of non-dismissible notifications. According to the official Android documentation:
If your app shows non-dismissable foreground notifications to users, Android 14 has changed the behavior to allow users to dismiss such notifications. This applies to apps that prevent users from dismissing foreground notifications by setting Notification.FLAG_ONGOING_EVENT through Notification.Builder#setOngoing(true) or NotificationCompat.Builder#setOngoing(true).
It seems that Android 14 and above enforces this behavior, making it impossible to create truly non-dismissible notifications, even for foreground services. Looks like we can no longer rely on making notifications non-dismissible.