I know I can wait for screen on/off events using PhoneEvents. But what I want to do is check if screen is on/off at any given time. To elaborate, when a notification comes, I want to do one thing if screen is on and another if screen is off.
I found this Java code. Could you please translate to B4A?
Sub IsScreenOn As Boolean
Dim p As Phone
If p.SdkVersion < 20 Then Return True 'not worth bothering with Android 4 devices
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim displays() As Object = ctxt.RunMethodJO("getSystemService", Array("display")).RunMethod("getDisplays", Null)
For Each display As JavaObject In displays
If display.RunMethod("getState", Null) <> 1 Then Return True '1 = Display.STATE_OFF
Next
Return False
End Sub