A apty Active Member Licensed User Longtime User Apr 16, 2014 #1 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 Code: Copy if <screen is off> then perform task a
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 Code: Copy if <screen is off> then perform task a
LucaMs Expert Licensed User Longtime User Apr 16, 2014 #2 You could read: http://www.b4x.com/android/help/phone.html#phoneevents Upvote 0
A apty Active Member Licensed User Longtime User Apr 16, 2014 #3 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
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
LucaMs Expert Licensed User Longtime User Apr 16, 2014 #4 I tried this: Code: Copy 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
I tried this: Code: Copy 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!
A apty Active Member Licensed User Longtime User Apr 16, 2014 #5 Thanks LucaMs. It works ..but once you put the screen on again for the second time, it doesn't work! Last edited: Apr 16, 2014 Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Apr 16, 2014 #6 Note that you can initialize it with Initialize instead of InitializeWithPhoneState (which adds a permission). The event will only be intercepted if the process is running. Upvote 0
Note that you can initialize it with Initialize instead of InitializeWithPhoneState (which adds a permission). The event will only be intercepted if the process is running.
LucaMs Expert Licensed User Longtime User Apr 16, 2014 #7 I had my app in foreground and I only expected that the screen went off (legacy). The ScreenOff event should raise at that moment or not? Upvote 0
I had my app in foreground and I only expected that the screen went off (legacy). The ScreenOff event should raise at that moment or not?
Erel B4X founder Staff member Licensed User Longtime User Apr 17, 2014 #8 Are you catching this event from a service? Upvote 0
LucaMs Expert Licensed User Longtime User Apr 17, 2014 #9 not, Main Activity Attachments LM_ScreenIsOff.zip LM_ScreenIsOff.zip 11.4 KB · Views: 320 Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Apr 17, 2014 #10 PhoneEvents should be used from a service. The activity is paused when the screen turns off so it cannot handle the event. Upvote 0
PhoneEvents should be used from a service. The activity is paused when the screen turns off so it cannot handle the event.
LucaMs Expert Licensed User Longtime User Apr 17, 2014 #11 Thank you, Erel, now everything is clear Upvote 0