How to send an SMS at a specific time in Android

  android, service

I would like to know how you would tackle this problem.

Years ago I wrote an App where one SMS were sent at a specific time for booking tickets when you parked your car (we have an Sms service for car parking in public).

I used an IntentService for that and it worked flawlessly. I calculated all the times when an SMS had to be fired (let us say at 09:02 a.m., 09:17 a.m., 09:34 a.m., 10:17 a.m., 10:34a.m., and so on).

But now with API >= 30, IntentService is deprecated and the Android OS stops my IntentService although I used a NotificationBuilder, PowerManager for doze mode, and so on.

I tried a hack with the AlarmManager.setExactAndAllowWhileIdle but the AlarmManager fires almost every second.

So, now I am trying to figure out how I can solve my problems:

  • App must be working even in background
  • doze mode
  • if I should use a JobIntentService, then it must be guaranted that the user can stop it!
  • and the SmsManager must be triggered in time!

Can someone tell me which approach I should take (JobService, JobScheduler, Service)?

Thanks for your hints!

Source: Android Questions