There are some situations where the phone should be prevented from going to sleep mode or screen lock mode. Eg. while watching a webpage/video or some presentations.
Java Code:
|
1 2 3 4 5 6 7 8 9 |
if(TASK_NOT_COMPLETED) { PowerManager pman = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wlock = pman.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag"); wlock.acquire(); //screen will stay on during this section.. //Do the tasks here } wlock.release(); |
Android Manifest.xml:
|
1 |
<uses-permission android:name="android.permission.WAKE_LOCK" /> |
Warning:
This is a resource intensive call. It uses a considerable amount of battery and processing power. Hence usage should be minimized or avoided if possible.



