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

Alarm 3.0.14 can't show notification on android #175

Closed steveng15 closed 7 months ago

steveng15 commented 7 months ago

Alarm plugin version Latest version 3.0.14

Describe the bug The alarm does not display notifications when the application is closed in android. However, it still sounds. If i'm using simulator ios, alarm showing notifications when the app is closed (killed). I have tried adding enableNotificationOnKill, but it has no effect. Can you help me figure out where the problem might be?

Is there any code that I need to show you?

Expected behavior Alarm show notification on android.

Device info

gdelataillade commented 7 months ago

Hi @steveng15

Make sure to follow the installation steps in the README. Also, have you asked for notification permission ? Do you have any error logs to share ?

steveng15 commented 7 months ago

I have followed the README. How to request notification permission?

This is my buildAlarm dan saveAlarm code

Screenshot 2024-04-02 at 10 02 57

i dont have error logs on my code. If i'm using android and i killed the app, alarm only ringing but don't show notification. But if i'm using simulator ios, alarm showing notification.

gdelataillade commented 7 months ago

Hi @steveng15

Your code looks good to me.

To make sure the notification permission was allowed you can check in your app' settings in the iOS/Android Settings app. If you need to ask the user to give the notification permission you can take a look at the example code. You should use the https://pub.dev/packages/permission_handler package.

steveng15 commented 7 months ago

Thanks for helping me. It's works.

notification permission on my phone is not allowed and then i'm allow this permission. I will adding permission handler for user to allow this notification permission. Thanks a lot @gdelataillade

steveng15 commented 7 months ago

Hi @gdelataillade

Sry, i have 1 question. In the notification that appears, where can I change the text that appears in the notification? I tried to add await Alarm.setNotificationOnAppKillContent(title, body) in the ring.dart file, providing static text, but it still doesn't change. The notification still uses the title and body from the existing properties.

gdelataillade commented 7 months ago

Hi @steveng15

For the notification that shows when app is killed, make sure to call Alarm.setNotificationOnAppKillConrent before calling Alarm.set. I recommend to call this just after calling await Alarm.init. Let me know if it works for you.

pnilkanth12 commented 7 months ago

HI @steveng15 I have same issue in when app killed then alarm not ring even i follow all steps which mention in package setup like all permission, add service in AndroidManifest.xml file

For now I have check in android device only

I used latest alarm package version alarm: ^3.0.14

Screenshot 2024-04-09 at 11 35 07 Screenshot 2024-04-09 at 11 55 50 Screenshot 2024-04-09 at 12 04 18

Note, I used Notification & Schedule Exact Alarm Permission is also Granted compileSdkVersion 34 targetSdkVersion 34 multiDexEnabled true

Added in main.dart file await Alarm.init(showDebugLogs: true);

Hi @gdelataillade I download your repo example code but still in same not ring alarm after app killed Please help me what I'm doing wrong

Thanks @gdelataillade @steveng15 in Advance.

gdelataillade commented 7 months ago

Hi @pnilkanth12

Have you granted the notification permission ?

If yes, please also try to:

pnilkanth12 commented 7 months ago

Hi @gdelataillade Yes I have given permission for Notification & Schedule Exact Alarm Permission and in my mobile battery optimisation is disable but still not working

Here app info screenshot may be you got more idea

WhatsApp Image 2024-04-09 at 14 03 44

in app foreground & background it's work perfect but when app killed then not work even not getting notification

gdelataillade commented 7 months ago

Hi @pnilkanth12

That's really weird. Could you try with another device ? This way we could know if the issue comes from the device or not.

pnilkanth12 commented 7 months ago

Hi @gdelataillade Thanks I have xiaomi phone in not work but after I check as you said in different device is Samsung so in Samsung device work

but in Samsung device app not open when alarm ring but only notification getting and notification click to open app alarm screen

Thanks

gdelataillade commented 7 months ago

@pnilkanth12 so you have the ring issue only with the xiaomi phone ?

pnilkanth12 commented 7 months ago

Hi @gdelataillade in Xiaomi phone nothing work when app state is killed and in Samsung phone when app killed then show only notification. not open app like when app foreground or background and alarm ring then show alarm screen open for stop and snooze alarm but not behave this in Samsung phone

gdelataillade commented 7 months ago

Hi @pnilkanth12

I don't have a Xiaomi device to test, but after doing some research I read about the "Autostart" permission in Xiaomi settings. Is that a thing ? What if you enable it ? Furthermore, I think there are more security settings that you could check. There is a Security app ? About Samsung, I think there is a "Appear on top" permission right ?

Please try to play with all these settings and let me know if you find something.

pnilkanth12 commented 7 months ago

Hi @gdelataillade Thanks a lot After enable "Autostart" permission it's working fine

gdelataillade commented 7 months ago

Hi @gdelataillade Thanks a lot After enable "Autostart" permission it's working fine

Good to know. I found this plugin that you could implement in your app to suggest your users to enable the Autostart permission: https://pub.dev/packages/auto_start_flutter

I will also mention it in the plugin's readme.

pnilkanth12 commented 7 months ago

Yeah that's great @gdelataillade

I have one suggestion to add one more map variable in AlarmSettings model class You can see in my code screenshot that for now I made a little change in this package code and added an extra variable, so suppose if there is any other information you would like to add, like an alarm note, etc., the developer can add in this variable and the alarm time they can get.

gdelataillade commented 7 months ago

@pnilkanth12 what is the purpose of passing an "information" to the alarm ? What is the use case ?

steveng15 commented 7 months ago

Hi @steveng15

For the notification that shows when app is killed, make sure to call Alarm.setNotificationOnAppKillConrent before calling Alarm.set. I recommend to call this just after calling await Alarm.init. Let me know if it works for you.

sorry for replying,

For Alarm.init() I stored it in main.dart This is my main.dart code:

Screenshot 2024-04-17 at 11 39 49

Where do I put Alarm.setNotificationOnAppKillContent? Is it when the alarm goes off which is on ring.dart

Screenshot 2024-04-17 at 11 40 31

I try use static data for Alarm.setNotificationOnAppKillContent and it's not work.