8

I want to send offline notification to user periodically at exact time (assume daily 9:00 AM). Right now I was trying workmanager Api but not able to find any method like AlarmsManager's setExact or setexactandallowwhileidle.

Only repeatInterval option is there that will be 24 (daily) in my case but how to send notification at exact time (9 : 00 am) .

Sagar
  • 23,903
  • 4
  • 62
  • 62
Ayush Jain
  • 563
  • 7
  • 11

2 Answers2

11

WorkManager isn't a replacement for AlarmManager. For your use case, AlarmManager sounds like the right solution. WorkManager is for deferrable tasks, not for executation of tasks at an exact time or while the system is in a low-power, idle mode such as doze mode.

Steve Miskovetz
  • 2,360
  • 13
  • 29
0

You can do with help of workmanager also. For that you have to calulate delayedtime between current time and next day's fixed time(in your case 9 AM). For details see this answer -> show notification using workmanager api

Note: Workmanager execution can not be fixed, it depends on system at given point of time.

Sadashiv
  • 841
  • 11
  • 19
  • yeah it will work but for making it periodic in the end again you have to depend on Alarm Manager. After my research I can say Alarm manager is best available API for perform any operation (repeat/single) based on fix/random time. – Ayush Jain Apr 22 '19 at 12:01
  • @AyushJain Alarm manager is not the best solution imo, because it shows alarm icon in the statusbar. So user may get confused if he didn't put any alarm in his phone. – Dev4Life Feb 16 '23 at 03:48