Android Question Scheduling Notification 14 days from now (Receiver)

walterf25

Expert
Licensed User
Longtime User
Hi all, I have the need to schedule a notification on my app 14 days from whenever the user completes certain tasks, I came across this thread here that requests the REQUEST_SCHEDULE_EXACT_ALARM permission so, My question is, will a Receiver work in this case, is there anything special I need to add in addition to the REQUEST_SCHEDULE_EXACT_ALARM permission? I still can not wrap my head around Receivers so I'm a little confused. Can I just simply calculate the ticks 14 days from whenever the user completes the tasks and StartServiceAtExact(ticks) without requiring the user to allow permissions to REQUEST_SCHEDULE_EXACT_ALARM?

How will the app handle the request in this case when the Notification needs to be issued 14 days in the future?

Thanks,
Walter
 

drgottjr

Expert
Licensed User
Longtime User
StartServiceAt should do the trick. no permission request is required by the user. the os will schedule the service to run
as close to the time requested and taking into consideration battery conservation and whatever else the device might be doing
at the time. however, there are some serious matters to take into account relating to network connections. if the device is
sleeping or dozing, network connections are cut. when the service is supposed to start (and assuming the service involved
network activity), the os will try to open a network connection, but there is no guarantee a connection will be successfully
made.

2 weeks in advance is a little risky; android will do what it feels it needs to do to preserve the battery and the device's
wellbeing. but,in theory, you can StartServiceAt 2 weeks from now and forget about it. anything involving the word "exact"
will involve either permissions or other restrictions.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Thank you for your advice, I have scheduled the Receiver to start in 30 minutes from now just to test, I will start incrementing the time, in 1 or 2 hours increments and see how it goes from there.

Regards,
Walter
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…