1

I have following handed-over existing code:

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

Based on here and here, is it to prevent the lock screen to appear? However, I am still able to lock my device. Can anyone advise me what is it for?

Community
  • 1
  • 1
Rendy
  • 5,572
  • 15
  • 52
  • 95

2 Answers2

1

From the docs:

public void disableKeyguard()

Disable the keyguard from showing. If the keyguard is currently showing, hide it. The keyguard will be prevented from showing again until reenableKeyguard() is called. A good place to call this is from Activity.onResume() Note: This call has no effect while any android.app.admin.DevicePolicyManager is enabled that requires a password.

This method requires the caller to hold the permission android.Manifest.permission.DISABLE_KEYGUARD.

So it really depends on where exactly you put this snippet exactly, and it definitely not means that you can't see your lock screen anymore. In addition, if you have some security in your lock screen, this snippet can bypass the security measure.

Community
  • 1
  • 1
yshahak
  • 4,996
  • 1
  • 31
  • 37
0

It is used to unlock your screen programmatically. Maybe you also noticed while testing, your lockscreen won't appear until you call reenableKeyguard() again. Although reenableKeyguard() will only work if you also called disableKeyguard() from your application.

is it to prevent the lock screen to appear? However, I am still able to lock my device.

But you do see your lockscreen?

Can anyone advise me what is it for?

Opening a notification from the lockscreen basically does this. It disables your keyguard (lockscreen) and launches the app.

Pang
  • 9,564
  • 146
  • 81
  • 122
Denny
  • 1,766
  • 3
  • 17
  • 37