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

Don't show notification when I killed app on android version 31+ #21

Closed songtoanht closed 1 year ago

songtoanht commented 1 year ago

final alarmSettings = AlarmSettings( id: 11, dateTime: triggerDate, assetAudioPath: 'assets/sample.mp3', loopAudio: true, notificationTitle: 'This is the title', notificationBody: 'This is the body', enableNotificationOnKill: true, ); await Alarm.set(alarmSettings: alarmSettings); await Alarm.setNotificationOnAppKillContent("lll", "ddd");

I call above function to show alarm. It works fine when the device runs on foreground and background. But when I killed the app it will show errors.

D/NotificationOnKillService(25880): Error showing notification D/NotificationOnKillService(25880): java.lang.IllegalArgumentException: com.gdelataillade.alarm.alarm_example: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. D/NotificationOnKillService(25880): Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles. D/NotificationOnKillService(25880): at android.app.PendingIntent.checkFlags(PendingIntent.java:375) D/NotificationOnKillService(25880): at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:458) D/NotificationOnKillService(25880): at android.app.PendingIntent.getActivity(PendingIntent.java:444) D/NotificationOnKillService(25880): at android.app.PendingIntent.getActivity(PendingIntent.java:408) D/NotificationOnKillService(25880): at com.gdelataillade.alarm.alarm.NotificationOnKillService.onTaskRemoved(NotificationOnKillService.kt:34) D/NotificationOnKillService(25880): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4641) D/NotificationOnKillService(25880): at android.app.ActivityThread.access$2000(ActivityThread.java:247) D/NotificationOnKillService(25880): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2091) D/NotificationOnKillService(25880): at android.os.Handler.dispatchMessage(Handler.java:106) D/NotificationOnKillService(25880): at android.os.Looper.loopOnce(Looper.java:201) D/NotificationOnKillService(25880): at android.os.Looper.loop(Looper.java:288) D/NotificationOnKillService(25880): at android.app.ActivityThread.main(ActivityThread.java:7839) D/NotificationOnKillService(25880): at java.lang.reflect.Method.invoke(Native Method) D/NotificationOnKillService(25880): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) D/NotificationOnKillService(25880): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

gdelataillade commented 1 year ago

Hi @songtoanht

Thanks for your interest in the package.

It looks like a flag is missing and it causes the NotificationOnKillService to fail. I'll take a close look at it soon but if you want feel free to contribute.

gdelataillade commented 1 year ago

I fixed the issue in the 0.2.3 release.

Please update the dependency on your project and let me know if the problem persists on your device by reopening this issue or another one.