Android Question AlarmManager no longer working

Graeme Tacon

Member
Licensed User
Longtime User
Hi,

I use the code below to schedule an alarm. This has been working fine until:
- I upgraded to B4A v8.00
- Upgraded my phone to Android v8.0.0
- Amended the target SDKversion in the my apps manifest to 28

Now, when the phone is asleep, the alarm doesn't trigger.

Which of the above is causing this to fail and what do I need to change to get it to work ?

Sub SetExactAndAllowWhileIdle (Time As Long, ServiceName As String, Action As String)
If Shared_GetDeviceID.SDKVersion < 23 Then
StartServiceAtExact(ServiceName, Time, True)
Else
Dim sPackageName As String = Shared_GetAppDetails.GetPackageName
Dim in As Intent
in.Initialize("", "")
in.SetComponent(sPackageName & "/." & ServiceName.ToLowerCase)
Dim jin As JavaObject = in
jin.RunMethod("setAction", Array(Action))
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
 
Top