Android Question Check if screen is off

apty

Active Member
Licensed User
Longtime User
How can i check if screen is off (or the phone is on sleep mode)? I would like to use ScreenOff phone event but i cant find a tutorial on the same. I would like to check if phone screen is off and then perform some tasks
e.g
B4X:
if <screen is off> then
perform task a
 

apty

Active Member
Licensed User
Longtime User
I have read it but still dont know how to use the phone event. Kindly help with sample code that checks if screen is off
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I tried this:
B4X:
Dim PhoneId As PhoneId
Dim PE As PhoneEvents
PE.InitializeWithPhoneState("PE", PhoneId)

Sub PE_ScreenOff (Intent As Intent)
    Log("Screen is OFF")
End Sub

Sub PE_ScreenOn (Intent As Intent)
    Log("Screen is ON")
End Sub

But PE_ScreenOn is raised even when the screen is turned off!
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
Thanks LucaMs. It works ..but once you put the screen on again for the second time, it doesn't work!
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…