Refrain your device from sleeping


How to refrain your device from sleeping with App Inventor

Note: with the extension feature, this workaround is now obsolete. Thank you MIT!
Now you can use my Tools Extension and its KeepScreenOn method instead.

As we know, after a certain time the Android device goes inactive. And if the device is sleeping, for example a countdown ends without alarm ... There is no perfect solution with App Inventor to refrain the device from sleeping, because all solutions will drain the battery of your device! Please use these workarounds wisely!

There are the following possibilities:

Description:
Include a videoplayer component width x height = 1x1, the videoplayer component must be visible on the screen. Upload a small dummy video. Start the video. In the video completed event start it again (or under some condition desired). By playing the video the application is running without sleep. It fades out the screen, then black, but the application still is running.

Note:
This does not work for all components, but it works fine with the Player component.

Thank you freesfx.co.uk for the car alarm sound.
You might be interested in the simplified countdown example for App Inventor 2 provided by richard.

Do you need help with your App Inventor project?

I can help you: for one hour I charge 25 USD.
Please contact me at info [at] puravidaapps [dot] com for details!
For questions about App Inventor, please use the App Inventor forum. Thank you.

Screenshots

App Inventor blocks

These are the blocks used for the "wake lock"


Further blocks used



Test

Tested successfully on Nexus 5 running Android 5.1.

Download


Developing and maintaining snippets, tutorials and extensions for App Inventor takes a lot of time.
I hope it saved some of your time. If yes, then you might consider to donate a small amount!

Donation amount:

or donate some mBTC to Bitcoin Address:
1Jd8kXLHu2Vkuhi15TWHiQm4uE9AGPYxi8
Bitcoin

Thank you! Taifun
 

Download aia file for App Inventor

Back to top of page ...

Creative Commons License
This work by Pura Vida Apps is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
with attribution (name=Pura Vida Apps and link to the source site) required.


Home | Snippets | Tutorials | Extensions | News | Forums | Links | Search | Contact