I use this code - based in this snippet from Erel - to start a service 3 times on day.
B4X:
Sub Service_Start (StartingIntent As Intent)
Dim t As Long
t = FindNextTime(Array As Double(8, 12+20/60, 18+40/60))
StartServiceAtExact(Me,t,True)
StopService(Me)
Service.StopAutomaticForeground
End Sub
Now my doubts:
1 - There is no StartReceiverAtExact. The new code - based in the StartReceiverAt - would it look like this?
B4X:
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
Dim t As Long
t = FindNextTime(Array As Double(8, 12+20/60, 18+40/60))
StartReceiverAt(Me,t,True)
End Sub
2 - There is no similar code to this lines? I can remove it?
B4X:
StopService(Me)
Service.StopAutomaticForeground
3 - Do I still need this permission in the manifest?
1.
StartServiceAtExact will work with receivers. The problem with this method is that Google made it more difficult to acquire the SCHEDULE_EXACT_ALARM on Android 13+. It is not a regular permission.
If exact scheduling isn't needed then simply use StartReceiverAt and remove the SCHEDULE_EXACT permission.