I use the code from this post to schedule time and show a notification. Works fine.
https://www.b4x.com/android/forum/threads/b4x-calculating-the-next-scheduled-time.65041/#content
Now I want to download a quote
https://www.b4x.com/android/forum/threads/b4x-okhttputils2-with-wait-for.79345/#content
and show the text in the notification.
I tried to put the code to download code in service start, before the notification, to test, but I get a problem: the notification restarted over and over.
How I can download the quote in the service and show it in the notification?
Thanks in advance for any tip.
https://www.b4x.com/android/forum/threads/b4x-calculating-the-next-scheduled-time.65041/#content
Now I want to download a quote
https://www.b4x.com/android/forum/threads/b4x-okhttputils2-with-wait-for.79345/#content
and show the text in the notification.
I tried to put the code to download code in service start, before the notification, to test, but I get a problem: the notification restarted over and over.
How I can download the quote in the service and show it in the notification?
Thanks in advance for any tip.
B4X:
Sub Service_Start (StartingIntent As Intent)
Log("shedule.service_start()")
Log("i´m started. So i´ll do my job NOW and reshedule me for the next time")
' DownloadQuote 'RESTART THE NOTIFICATION SEVERAL TIMES
Dim n As Notification
n.Initialize
n.Icon = "icon"
n.AutoCancel = True
n.SetInfo(Application.LabelName, "Quote of the day", Main)
n.Notify(1)
Dim t As Long
t = FindNextTime(Array As Double(17+6/60, 17+7/60, 17+8/60))
Log($"Next time is: $Time{t}"$)
StartServiceAt(Me,t,True)
StopService("")
End Sub
Sub DownloadQuote
Dim j As HttpJob
j.Initialize("", Me) 'name is empty as it is no longer needed
j.Download("http://quotesondesign.com/wp-json/posts?filter[orderby]=rand")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
'The result is a json string. We parse it and log the fields.
Dim jp As JSONParser
jp.Initialize(j.GetString)
Dim quotes As List = jp.NextArray
For Each quot As Map In quotes
Log("Title: " & quot.Get("title"))
Log("Content: " & quot.Get("content"))
Next
End If
j.Release
End Sub