Turn On (wake) screen

qsrtech

Active Member
Licensed User
Longtime User
Hi, I've found this code online, can anyone help make it work in b4a?

It's suppose to be able to turn the screen back on if it's sleeping.

B4X:
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "tag");
wl.acquire();

Thanks!
John
 

qsrtech

Active Member
Licensed User
Longtime User
wake lock

Hi, thank you for your suggestion. I'm already using the partiallock and keepalive but they only seem to prevent the screen from going to sleep. I'd like to prevent screen burn in by allowing the screen to go to sleep and then turn it back on when there is an event. I'm pretty sure it's possible cause I have an alarm app on my phone (4.03) which seems to do this. Any other solution? I'm pretty sure I need to use the type of wake lock I described earlier.

From Android Developer:
ACQUIRE_CAUSES_WAKEUP Normal wake locks don't actually turn on the illumination. Instead, they cause the illumination to remain on once it turns on (e.g. from user activity). This flag will force the screen and/or keyboard to turn on immediately, when the WakeLock is acquired. A typical use would be for notifications which are important for the user to see immediately.
 
Upvote 0

qsrtech

Active Member
Licensed User
Longtime User
Almost there

I've managed to get this code working:
B4X:
   Dim obj1,obj2,obj3 As Reflector
   obj1.Target = obj1.GetContext
   obj2.Target = obj1.RunMethod2("getSystemService", "power", "java.lang.String")

up until here, the value of "268435456"(ACQUIRE_CAUSES_WAKEUP) fails with an illegal argument exception, however if I use "1"(PARTIAL_WAKE_LOCK) it works fine
B4X:
   obj3.Target = obj2.RunMethod3("newWakeLock","268435456", _
"java.lang.int","Mytag", "java.lang.String")

Any pointers?

UPDATE: changed it to "268435482" which adds "26" for a FULL_WAKE_LOCK

Now to have the "lock screen" removed after waking up the device. Again, must be possible cause my alarm app does it.
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Check the documentation on Android Developers (google for that, sorry not on my pc). Lookup Powermanager.

-------------------
Sent via Tapatalk
 
Last edited:
Upvote 0
Top