how to keep android display from sleeping or dimming while plugged in?

832 Views Asked by At

i have some nexus 7's (2013) that are not rooted and have api 6.0.1 with may security patches.

i have stay awake on in developer options. i have everything off under the display settings except for sleep (which can not be turned off and is set to 30 minutes). despite this, the tablet dims after about 30 minutes.

i tried acquiring and releasing wakelock in on resume and on pause with no joy.

adb shell settings put global stay_on_while_plugged_in 0 - does not work either (neither does a value of 7 - the original value was 3)

2

There are 2 best solutions below

2
nullvoid On BEST ANSWER

Here is the google documentation: https://developer.android.com/training/scheduling/wakelock.html

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }
}
0
thailey01 On

Just getting the wake_lock permission in the manifest file works for me.