Sub SetExactAndAllowWhileIdle (Time As Long, ServiceName As String)
Dim p As Phone
If p.SdkVersion < 23 Then
StartServiceAtExact(ServiceName, Time, True)
Else
Dim in As Intent
in.Initialize("", "")
in.SetComponent(Application.PackageName & "/." & ServiceName.ToLowerCase)
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))
Dim amc As JavaObject
amc.InitializeNewInstance("android.app.AlarmManager$AlarmClockInfo", Array( _
Time, Null))
am.RunMethod("setAlarmClock", Array(amc, pi))
End If
End Sub