I have this example (in attached) that schedules a service to show a notification every thurday at 10:30 AM.
In Android 4 it works, but in Android 9 the notification run one time in the first week, but don't show in the next weeks.
I think the Android 9 kills the process.
I checked this post from @Erel Background location tracking, but I don't what is the problem and how to fix it.
Thanks in advance for any help.
Code:
In Android 4 it works, but in Android 9 the notification run one time in the first week, but don't show in the next weeks.
I think the Android 9 kills the process.
I checked this post from @Erel Background location tracking, but I don't what is the problem and how to fix it.
Thanks in advance for any help.
Code:
B4X:
Sub Service_Start (StartingIntent As Intent)
If Starter.running <> True Then
Dim n As Notification
n.Initialize2(n.IMPORTANCE_HIGH)
n.Icon = "icon"
n.AutoCancel = True
n.Vibrate = False
n.Sound = True
n.SetInfo2("Thursday", "Test of notification...", "odNotifica", Main)
n.Notify(1)
End If
Dim t As Long
t = Functions.SetNextDayAlarm(5, 10, 30) 'thurday
Log("SetNextAlarmDate> " & DateTime.Date(t) & " " & DateTime.Time(t))
StartServiceAtExact(Me,t,True)
StopService(Me)
Service.StopAutomaticForeground
End Sub
B4X:
Sub SetNextDayAlarm(DayOfWeek As Int, Hour As Int, Minute As Int) As Long
Dim day As Int = DateTime.GetDayOfWeek(DateTime.Now)
If day >= DayOfWeek Then DayOfWeek = DayOfWeek + 7
Dim d As Long = DateTime.Add(DateTime.Now, 0, 0, DayOfWeek - day)
Return DateUtils.SetDateAndTime(DateTime.GetYear(d), DateTime.GetMonth(d), DateTime.GetDayOfMonth(d), Hour, Minute, 0)
End Sub
B4X:
Sub StartNotification
Dim t As Long
t = Functions.SetNextDayAlarm(5, 10, 30) 'thurday
Log(t)
Log("SetNextAlarmDate> " & DateTime.Date(t) & " " & DateTime.Time(t))
CancelScheduledService(Alarme)
StartServiceAtExact(Alarme,t,True)
End Sub