I have an Android (version 1.5) application which needs to be constantly running when a button is pressed. So, when a Button
is pressed I would like the phone to remain on and not want the screen or CPU to time-out.
When another Button
is pressed I would like the phone to be back to normal and time-out as per user settings.
Update: As suggested by Steve Pomeroy, this might be a better way to do it.
You can use a WakeLock
that requires the following permission:
<uses-permission android:name="android.permission.WAKE_LOCK" />
Here is how you aquire and release a WakeLock
:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag");
wl.acquire();
// wake locked...
wl.release();
Depending on your requirements you might be able to use a different type of WakeLock
.
Instead of using a wakelock, you should consider the solution proposed here: Force Screen On
It is much easier to use and doesn't have the potential of accidentally wasting the user's batteries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With