This article describes the method of Android programming to prohibit system locking and unlocking the screen. Share it for your reference, as follows:
need:
At a certain moment, the task is executed, close the screen, and then turn on the screen to continue the task.
Usually, if the screen is not set to be on, the system will automatically lock the screen. After locking the screen, it cannot be unlocked from the code (question), so my approach is to only let the system turn off the screen, but not lock the screen!
WakeLock lock, unLock; KeyguardManager km; KeyguardLock kl;
unLock = (PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright"); // Get the keyboard lock manager objectkm = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); kl = ("unLock");
void lockScreen() { // Lock screen (); // Release wakeLock and turn off the lights if(()) (); } void unLockScreen() { // Light up the screen if(!()) (); // Unlock (); }
Test code. After calling the test code, you manually press the power button to lock the screen. After 5 seconds, you will see the screen light up.
{ lockScreen(); getListView().getHandler().postDelayed(new Runnable() { @Override public void run() { unLockScreen(); } }, 5000); break; }
I hope this article will be helpful to everyone's Android programming design.