Android Question Still can't bypass doze mode

NeoTechni

Well-Known Member
Licensed User
Longtime User
Today my alarm went off five minutes late. Given it was never late before doze mode I assume it's the culprit again

I've read up on it

The doc mentioned above says, "Alarms set with setAlarmClock() continue to fire normally — the system exits Doze shortly before those alarms fire." If alarm clock apps get changed to call this (new in Lollipop) method, they should wake on time. (The JavaDocs don't mention this feature.)

https://plus.google.com/+AndroidDevelopers/posts/94jCkmG4jff

How do I use this API instead?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Based on the documentation it should wake up the device: https://developer.android.com/refer...ileIdle(int, long, android.app.PendingIntent)

You can use this code to call AlarmManager.setAlarmClock. It will show an alarm indicator in the status bar.
B4X:
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
 
Upvote 0

Graeme Tacon

Member
Licensed User
Longtime User
Hi

I'm using Erel's code to add the alarm indicator in the status bar:

Dim amc AsJavaObject
amc.InitializeNewInstance("android.app.AlarmManager$AlarmClockInfo", Array(Time, Null))
am.RunMethod("setAlarmClock", Array(amc, pi))

What code do I use to remove that indicator ?

Thanks
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
I know. Their ideas about security are a little to obsessive. They removed the ability for third party apps to answer phone calls, and made it so only one app can handle SMS messages, which neutered a popular dialer program I made....
 
Upvote 0
Top