#Region Service Attributes
#StartAtBoot: true
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private rv As RemoteViews
Public textsize As Int
End Sub
Sub Service_Create
rv = ConfigureHomeWidget("frmWidget", "rv", 0, "HomeClock", True)
rv.SetTextSize("lblTime", textsize)
DateTime.TimeFormat="HH:mm"
DateTime.DateFormat="EEEE, dd MMM"
End Sub
Sub Service_Start (StartingIntent As Intent)
'Log(StartingIntent)
'Reschedule the service every minute, so the clock gets updated correctly
'StartServiceAt(Me, TimeToNextMinute, False)
StartServiceAtExact2(Me, TimeToNextMinute)
rv_RequestUpdate
If rv.HandleWidgetEvents(StartingIntent) Then Return
End Sub
Sub Service_Destroy
End Sub
Sub StartServiceAtExact2 (ServiceName As String, Time As Long)
Log("ServiceName=" & ServiceName)
Dim p As Phone
If p.SdkVersion < 23 Then
StartServiceAtExact(ServiceName, Time, True)
Else
Dim in As Intent, ctxt As JavaObject, pi As JavaObject
in.Initialize("", "")
in.SetComponent(Application.PackageName & "/." & ServiceName.ToLowerCase)
ctxt.InitializeContext
Dim am As JavaObject = ctxt.RunMethod("getSystemService", Array("alarm"))
pi = pi.InitializeStatic("android.app.PendingIntent").RunMethod("getService", Array(ctxt, 1, in, 134217728))
am.RunMethod("setExactAndAllowWhileIdle", Array(0, Time, pi))
End If
End Sub
'Calculate the time to the next full minute
Sub TimeToNextMinute As Long
Dim ret As Long
ret = DateTime.Now + DateTime.TicksPerMinute
ret = ret - (ret Mod DateTime.TicksPerMinute)
Return ret
End Sub
Sub SetTime
rv.SetText("lblTime", DateTime.Time(DateTime.Now))
rv.SetText("lblDate", DateTime.Date(DateTime.Now))
End Sub
Sub rv_RequestUpdate
SetTime
rv.UpdateWidget
End Sub
Sub rv_Disabled
StopService("")
End Sub