Home > Software design >  Block Android Notification during night time
Block Android Notification during night time

Time:11-11

I am trying to find documentation or a cleaner way of not showing notification(programmatically) during nighttime (sleeping hours). I have a service that periodically checks if certain conditions are met and then I fire the notification. I would want to avoid this when the user is sleeping.

CodePudding user response:

I don't really think you need to. If the user wants to block notifications, they'll put the device in Do Not Disturb mode which blocks all notification. I have one set to automatically turn on at night and off in the morning. Bonus- when the DND turns off, I get all the notifications I miss. This is a feature of the Android OS.

If you really wanted to do this- just check the time before you put up a notification. If its too late, don't fire it. Optionally, set an alarm for when you think its late enough, and decide if the user should see them now.

CodePudding user response:

Do you mean to keep running the program at night without using notifications? You only need to use WorkManager, JobScheduler or AlarmManager to achieve.

  • Related