Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent screen lock on dimming/standby while using android app?

I'm developing an application and the last touch I need to put on it is preventing the screen to lock when the device goes into standby (screen off). The exact behavior as Google Navigation.

I'm wondering what, programatically I will have to use to keep this feature enable the entire time while using the app?

like image 576
Braydon Batungbacal Avatar asked Dec 05 '22 16:12

Braydon Batungbacal


2 Answers

writing the following code to your xml file will prevent the screen from locking

android:keepScreenOn="true"
like image 53
5w4rley Avatar answered Dec 07 '22 05:12

5w4rley


In the onCreate of your activity after the setContentView use this:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Not tried it myself.

like image 25
Niraj Gupta Avatar answered Dec 07 '22 04:12

Niraj Gupta