androidsettingsdisplayscreen-lock

Android application - disable screen lock


I am trying to disable automatic screen lock of my phone while application running. I used the below permissions and code,

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>

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

The phone automatic lock is disabled but, the display light is off (which is set the display time out in settings).

How can I enable the display also?


Solution

  • Add the WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON flag to keep the screen on:

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