SoFunction
Updated on 2025-03-08

Android lights up the screen or screen unlocks and locks and other related permissions implementation code

1. The Android screen is always on/lit
Copy the codeThe code is as follows:

//Keep the screen on
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = (PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, LOCK_TAG);
();

Copy the codeThe code is as follows:

//Release the screen to always turn on the lock
if(null != mWakeLock) {
    ();
}

2. Android screen unlocking and locking
Copy the codeThe code is as follows:

//Screen unlock
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
KeyguardLock keyguardLock = (LOCK_TAG);
();
//Screen lock
();

3. Related permissions
Copy the codeThe code is as follows:

<uses-permission android:name=".DISABLE_KEYGUARD" />
<uses-permission android:name=".WAKE_LOCK" />