how to lock the android programatically
问题 i want to lock the phone when i click the lock button.anybody please help with simple code.i tried with part of code from API_Demos but it shows some error. 回答1: You can lock the Android's screen programmatically using the LockScreen class like so: KeyguardManager mgr = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE); KeyguardLock lock = mgr.newKeyguardLock(KEYGUARD_SERVICE); lock.reenableKeyguard(); Take a look at the LockScreen class here. 回答2: The code: KeyguardManager mgr =