Android Question B4A v8.00 StartServiceAt / StartServiceAtExact / SetExactAndAllowWhileIdle

Pendrush

Well-Known Member
Licensed User
Longtime User
Do we still need this code in B4A 8.00+:
B4X:
Sub SetExactAndAllowWhileIdle (Time As Long, ServiceName As String)
    Dim p As Phone
    If p.SdkVersion < 23 Then
        StartServiceAtExact(ServiceName, Time, True)
    Else
        Dim intex As Intent
        intex.Initialize("", "")
        intex.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, intex, 134217728))
        am.RunMethod("setExactAndAllowWhileIdle", Array(0, Time, pi))
    End If   
End Sub

or StartServiceAtExact(ServiceName, Time, True) will do the job on all SDK versions?
 
Top