简体   繁体   中英

Using disableKeyguard and reenableKeyguard to lock and unlock

In my application I am using disableKeyguard and reenableKeyguard to lock and unlock a screen with proximity and accelerometer sensors respectively. My application working with some bugs. If user unlocks a screen by dragging (without using my app) then my application will not lock !. How to prevent this issue? How to fix this bug? plz help me.

Is there any other way to lock and unlock ?

thanks in advance.

reenableKeyguard

void reenableKeyguard() Reenable the keyguard. The keyguard will reappear if the previous call to disableKeyguard() caused it to be hidden. A good place to call this is from onPause() Note: This call has no effect while any DevicePolicyManager is enabled that requires a password.

This method requires the caller to hold the permission DISABLE_KEYGUARD.

Your app has to be the one to call disableKeyguard() first, else you cannot lock it using reenableKeyguard()

Source: https://developer.android.com/reference/android/app/KeyguardManager.KeyguardLock.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM