Hi all,
my target is to send local notificationin certain days (Wed and Fri) and at certain hours (in my example at 15.37 and 15.39)
A Main Module
And a Notif Service
I attach the code.
The issue is that when i reboot the device the notification is sent without control any time or day, could you please give me an help to solve this problem?
Thanks in advance!
my target is to send local notificationin certain days (Wed and Fri) and at certain hours (in my example at 15.37 and 15.39)
A Main Module
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim NowDay As Long
End Sub
Sub Activity_Create(FirstTime As Boolean)
NowDay = DateTime.DateParse(DateTime.Date(DateTime.Now))
StartServiceAt(Notif,NowDay,True)
End Sub
And a Notif Service
B4X:
#Region Service Attributes
#StartAtBoot: True
#End Region
Sub Process_Globals
End Sub
Sub Service_Create
End Sub
Sub Service_Start (StartingIntent As Intent)
Log(StartingIntent.Action)
Dim p As Period
p.Days = 1
StartServiceAt(Me, Min(NextTimeInstance(15, 31), NextTimeInstance(15, 34)) ,True)
Dim tomorrow As Long = DateUtils.AddPeriod(DateTime.Now, p)
Dim wed As Int = 4
Dim fri As Int = 6
Dim today As Int = DateTime.GetDayOfWeek(DateTime.Now)
If today <> wed AND today <> fri Then
Else
Dim n As Notification
n.Initialize
n.Icon = "icon"
n.SetInfo("Title", "Message", Main)
n.Notify(1)
End If
End Sub
Sub NextTimeInstance (hours2 As Int, minutes2 As Int) As Long
Dim today As Long = DateTime.Now
today = DateUtils.SetDateAndTime(DateTime.GetYear(today), DateTime.GetMonth(today), _
DateTime.GetDayOfMonth(today), hours2, minutes2, 0)
If today < DateTime.Now Then
Dim p As Period
p.Days = 1
Dim tomorrow As Long = DateUtils.AddPeriod(today, p)
Return tomorrow
Else
Return today
End If
End Sub
I attach the code.
The issue is that when i reboot the device the notification is sent without control any time or day, could you please give me an help to solve this problem?
Thanks in advance!