When my application is running or has closed just a few minutes ago, then the StartServiceAtExact works. When the device is off and the service is set to run a few hours later, it does not wake the device. I am using android-23. I have tried this code first:
And I have also tried this: -
B4X:
StartServiceAtExact(alarms, NextTimeInstance(DateTime.GetHour(t), DateTime.GetMinute(t)), True)
And I have also tried this: -
B4X:
SetExactAndAllowWhileIdle(NextTimeInstance(DateTime.GetHour(t), DateTime.GetMinute(t)),"alarms")
Sub SetExactAndAllowWhileIdle (t As Long, ServiceName As String)
Dim p As Phone
If p.SdkVersion < 23 Then
StartServiceAtExact(ServiceName, NextTimeInstance(DateTime.GetHour(t), DateTime.GetMinute(t)), 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, NextTimeInstance(DateTime.GetHour(t), DateTime.GetMinute(t)), pi))
End If
End Sub