Hi everyone,
sorry for my english. I am helping myself with google translator.
For educational purposes, I'm trying to write a widget that reads a Json file and shows what hypothetical users can give to the garbage collection service.
If it worked I would also try to publish it in the play store but this is not the question.
As you can read from line 23, the widget should update the text every 30 minutes but it simply remains impassive and does not update. Could someone explain to me where am I wrong? I'm wasting a lot of time on it. This is my first exercise with b4a.
For completeness I have attached the export of the project from b4a.
Thank you
sorry for my english. I am helping myself with google translator.
For educational purposes, I'm trying to write a widget that reads a Json file and shows what hypothetical users can give to the garbage collection service.
If it worked I would also try to publish it in the play store but this is not the question.
As you can read from line 23, the widget should update the text every 30 minutes but it simply remains impassive and does not update. Could someone explain to me where am I wrong? I'm wasting a lot of time on it. This is my first exercise with b4a.
For completeness I have attached the export of the project from b4a.
Thank you
Full Starter Service of the widget:
#Region Service Attributes
#StartAtBoot: True
'#ExcludeFromLibrary: True
#End Region
Sub Process_Globals
Log ("Process_Globals " & DateTime.Date(DateTime.now))
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim ObjRV As RemoteViews
End Sub
Sub Service_Create
DateTime.DateFormat="hh:mm:ss:mm"
'This is the program entry point.
Log ("Service_Create " & DateTime.Date(DateTime.now))
'This is a good place to load resources that are not specific to a single activity.
ObjRV = ConfigureHomeWidget("main", "ObjRV", 30,"Cosa Butto Oggi", True)
End Sub
Sub Service_Start (StartingIntent As Intent)
Log ("Service_Start " & DateTime.Date(DateTime.now))
Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
If StartingIntent.Action = "android.appwidget.action.APPWIDGET_DELETED" Then Return
If ObjRV.HandleWidgetEvents(StartingIntent) = False Then
'prendo il Jason con il calendario degli scarichi
'Wait For(DownloadCalendario) Complete (calendarioSemplificato As String)
ObjRV_RequestUpdate '(calendarioSemplificato)
'Sleep (0)
End If
'ObjRV_RequestUpdate
End Sub
Sub Service_TaskRemoved
'This event will be raised when the user removes the app from the recent apps list.
Log ("Service_TaskRemoved " & DateTime.Date(DateTime.now))
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Log (" Application_Error " & DateTime.Date(DateTime.now))
Return True
End Sub
Sub Service_Destroy
End Sub
Sub ObjRV_RequestUpdate '(calendario As String)
Log ("ObjRV_RequestUpdate " & DateTime.Date(DateTime.now))
Wait For(DownloadCalendario) Complete (calendarioSemplificato As String)
AggiornaContentutoWidget (calendarioSemplificato)
ObjRV.UpdateWidget
End Sub
Sub ObjRV_Destroy
Log ("ObjRV_Destroy " & DateTime.Date(DateTime.now))
StopService("")
End Sub
Sub AggiornaContentutoWidget (calendario As String)
Log ("AggiornaContentutoWidget " & DateTime.Date(DateTime.now))
'Verifico che giorno della settimana è
Dim giorno As String = getGiornoDellaSettimana
'passo il calendario ad un parser Jason per estrarre i rifiuti che si raccolgono oggi
Dim messaggio As String = decodeCalendario(calendario, giorno )
Dim dataOra As String
dataOra = DateTime.Date(DateTime.now)
'imposto il testo sul widget
ObjRV.SetText("Label1", messaggio)' & Chr(10) & DateTime.Now )
ObjRV.SetText("Label2", dataOra & " Controlla sul sito della Patrimonio eventuali variazioni.")
End Sub
Sub ObjRV_Disabled
Log ("ObjRV_Disabled " & DateTime.Date(DateTime.now))
StopService("")
End Sub
Sub DownloadCalendario As ResumableSub
Log ("DownloadCalendario " & DateTime.Date(DateTime.now))
'scarico il jason dal sito aziendale
Dim job As HttpJob
Dim calendarioJson As String
job.Initialize("", Me)
job.Download([MY JSON STRING URL])
Wait For (job) JobDone(job As HttpJob)
If job.Success Then
calendarioJson = job.GetString
End If
job.Release
Return calendarioJson
End Sub
Sub getGiornoDellaSettimana As String
Log ("getGiornoDellaSettimana " & DateTime.Date(DateTime.now))
Dim days() As String = Array As String("","Domenica" , "Lunedì" , "Martedì", "Mercoledì" ,"Giovedì" ,"Venerdì" ,"Sabato" )
'Dim days() As String = Array As String("","Domani il servizio di raccolta non passa", "dalle 20.00 di oggi alle 6.00 di domani puoi buttare l'organico" , "dalle 20.00 di oggi alle 6.00 di domani puoi buttare plastica e lattine di alluminio", "dalle 20.00 di oggi alle 6.00 di domani puoi buttare organico e sfalci" ,"dalle 20.00 di oggi alle 6.00 di domani puoi buttare l'indifferenziato", "dalle 20.00 di oggi alle 6.00 di domani puoi buttare l'organico" , "dalle 20.00 di oggi alle 6.00 di domani puoi buttare carta e vetro")
Dim oggi As Int = DateTime.GetDayOfWeek(DateTime.Now)
Dim domani As Int = oggi + 1
Dim giornoDellaSettimana As String = days(domani)
Return giornoDellaSettimana
End Sub
Sub decodeCalendario (calendarioSettimanale As String, giornoDellaSettimana As String ) As String
Log ("decodeCalendario " & DateTime.Date(DateTime.now))
'estraggo l'rsu del giorno dato dal tracciato Json
Dim parser As JSONParser
Dim Map1 As Map
Dim rsuDelGiorno As String
parser.Initialize(calendarioSettimanale)
Map1 = parser.NextObject
rsuDelGiorno = Map1.Get(giornoDellaSettimana)
Return rsuDelGiorno
End Sub