Hello,
My application needs to send a notification every day (conditional) at the same time.
But it is the user of the application who must set the time of sending.
Here is my code but it does not work. What's wrong, what is the correct code?
In Main Module
In Module Service "Alarme"
I tried multis ServiceStartAt formulas, nothing works.
Thank you for your help
My application needs to send a notification every day (conditional) at the same time.
But it is the user of the application who must set the time of sending.
Here is my code but it does not work. What's wrong, what is the correct code?
In Main Module
B4X:
Sub BtnParamHeure_Click
Dim HeureAverto as long
Dim td As TimeDialog
Dim txt As String
txt = "14:30:00"
Td.Hour = DateTime.GetHour(DateTime.TimeParse(txt))
'DateTime.TimeParse("16:13:00")
Td.Minute = DateTime.GetMinute(DateTime.TimeParse(txt))
Td.Is24Hours = True
ret = Td.Show("Entrer l'heure où voulez être prévenue", "Heure de l'avertissement", "OK", "Annuler", "", Null)
If ret = DialogResponse.POSITIVE Then
HeureAverto = Td.TimeTicks 'Date choisie par le picker
LblParamHeure.Text = DateTime.Time(HeureAverto)
Else
Return
End If
'Lance la notif si coché
MyHeure = DateTime.Time(HeureAverto)
If ChkNotif.Checked=True Then
StartServiceAt("Alarme",DateTime.TimeParse(MyHeure),True)
Else
'StopService(Alarme) 'Met fin à la notif
CancelScheduledService(Alarme)
End If
End Sub
In Module Service "Alarme"
B4X:
Sub Service_Start (StartingIntent As Intent)
RECUP_alarme 'Récupère les variables dont notif, alarm et HeureAverto
If notif =True Then
Dim TheHeure As String
DateTime.TimeFormat = "HH:mm"
TheHeure = DateTime.Time(HeureAverto)
If alarm = True Then
Dim n As Notification
n.Initialize
n.Icon = "logo"
n.SetInfo("Contraception", alerte, "Main")
'Change Main (above) to "" if this code is in the main module.
n.Vibrate = True
n.Notify(1)
End If
StartServiceAt("",TheHeure + (60000 * 60 * 24) ,True)
'StartServiceAt("",DateTime.TimeParse(TheHeure),True)
'StartServiceAt("",DateTime.TimeParse(TheHeure + (60000 * 60 * 24) ),True)
Else
CancelScheduledService("")
End If
End Sub
I tried multis ServiceStartAt formulas, nothing works.
Thank you for your help
Last edited by a moderator: