8

I’d like to disable/delay the lock screen programmatically. In looking into this, KeyguardManager is depreciated/doesn't work consistently, FLAG_DISMISS_KEYGUARD is not an option because I want to do this in the background, I don't want to use WakeLock for battery reasons, Device Administration does not appear to be capable of this and, while SCREEN_OFF_TIMEOUT is available to control when the screen sleeps, I was unable to find a similar timeout for the screen lock.

What am I missing here? Thanks.

Ali
  • 9,800
  • 19
  • 72
  • 152
Bink
  • 1,934
  • 1
  • 25
  • 41

3 Answers3

14

try this, it will keep awake the screen/ display , as long as the activity is on top. getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Also this does not require any permission in manifest.

Swapnil Kale
  • 2,620
  • 2
  • 23
  • 21
3

the answer of @nandeesh is working but it's deprecated , to disable lock screen use flags :

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
Houcine
  • 24,001
  • 13
  • 56
  • 83
2

Did you try this?

KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();

Add

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

You can disable the keyguard using this.

nandeesh
  • 24,740
  • 6
  • 69
  • 79