:name="android.permission.DISABLE_KEYGUARD" /> //锁屏、唤醒相关private KeyguardManager km;private KeyguardLock kl;private PowerManager pm;p_keyguardmanager.disablekeyguard 密码界面">
当前位置:   article > 正文

解锁、唤醒屏幕用到KeyguardManager,KeyguardLock,PowerManag_keyguardmanager.disablekeyguard 密码界面

keyguardmanager.disablekeyguard 密码界面

所需权限:

<uses-permission androidname="android.permission.WAKE_LOCK" />

 

<uses-permission androidname="android.permission.DISABLE_KEYGUARD" />

 

//锁屏、唤醒相关

private KeyguardManager  km;

private KeyguardLock kl;

private PowerManager pm;

private PowerManager.WakeLock wl;

 

 

 

private void wakeAndUnlock(boolean b)

{

       if(b)

       {

              //获取电源管理器对象

              pm=(PowerManager) getSystemService(Context.POWER_SERVICE);

 

              //获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag

              wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");

 

              //点亮屏幕

              wl.acquire();

             

              //得到键盘锁管理器对象

              km= (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);

              kl = km.newKeyguardLock("unLock");

 

              //解锁

              kl.disableKeyguard();

       }

       else

       {

              //锁屏

              kl.reenableKeyguard();

             

              //释放wakeLock,关灯

              wl.release();

       }

      

}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/889071
推荐阅读
相关标签
  

闽ICP备14008679号