SoFunction
Updated on 2025-03-11

Android wake-up and unlock screen code examples


//Lock screen, wake up related
private KeyguardManager  km;
private KeyguardLock kl;
private PowerManager pm;
private wl;
 
 
 
private void wakeAndUnlock(boolean b)
{
       if(b)
       {
//Get the power manager object
              pm=(PowerManager) getSystemService(Context.POWER_SERVICE);
 
//Get the object, the following parameter| indicates that two values ​​are passed in at the same time, and the last one is the tag for debugging
              wl = (PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");
 
//Light up the screen
              ();
            
//Get the keyboard lock manager object
              km= (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
              kl = ("unLock");
 
//Unlock
              ();
       }
       else
       {
//Lock screen
              ();
            
//Release wakeLock and turn off the lights
              ();
       }
     
}