Sub Service_Start (StartingIntent As Intent)
'Call the start service code and set the next time.
SetExactAndAllowWhileIdle(TimeToNextMinute, "ServiceEmad")
ToastMessageShow("Time for SetExact: " & DateTime.GetHour(TimeToNextMinute) & ":" & _
DateTime.GetMinute(TimeToNextMinute), True)
End Sub
Sub Service_Destroy
End Sub
' Misc. sub routines.
'--------------------
'TIME TO NEXT WHOLE MINUTE
Sub TimeToNextMinute As Long
Dim Ret As Long
Ret = DateTime.Now + (DateTime.TicksPerMinute * 15) '15 = 15 minutes
Ret = Ret -(Ret Mod DateTime.TicksPerMinute)
Return Ret
End Sub
'SET EXACTLY
Sub SetExactAndAllowWhileIdle(Time As Long, ServiceName As String)
Dim Phone As Phone
If Phone.SdkVersion < 23 Then
StartServiceAtExact(ServiceName, Time, True)
Else
Dim in As Intent
in.Initialize("", "")
in.SetComponent(Application.PackageName & "/." & ServiceName.ToLowerCase)
Dim Jin As JavaObject = in
Jin.RunMethod("setAction", Array(Null))
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim Am As JavaObject = ctxt.RunMethod("getSystemService", Array("alarm"))
Dim Pi As JavaObject
Pi = Pi.InitializeStatic("android.app.PendingIntent").RunMethod("getService", _
Array(ctxt, 1, in, 134217728))
Am.RunMethod("setExactAndAllowWhileIdle", Array(0, Time, Pi))
End If
End Sub