Android lock screen to prevent the phone codes

  1. Adding code to the class files;
# 注意pManager和mWakeLock需要提前定义
@Override  
protected void onResume() {  
   super.onResume();  
   pManager = ((PowerManager) getSystemService(POWER_SERVICE));  
   mWakeLock = pManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK  
                | PowerManager.ON_AFTER_RELEASE, TAG);  
   mWakeLock.acquire();  
}  
      
@Override  
protected void onPause() {  
   super.onPause();         
   if(null != mWakeLock){  
      mWakeLock.release();  
   }  
}  
  1. After the declaration of competence, the code takes effect.
# 注意要加权限AndroidManifest.xml文件中加入  
<uses-permission android:name="android.permission.WRITE_SETTINGS" /> 
Published 21 original articles · won praise 11 · views 20000 +

Guess you like

Origin blog.csdn.net/y609532842/article/details/104682145