android 禁用解锁

阅读更多
启动一个服务禁用解锁就行了。
    KeyguardManager keyguardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
     KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("Charge");
     keyguardLock.disableKeyguard();//禁用解锁



    KeyguardLock.reenableKeyguard(); //开启锁机


这里值得注意的是:开启锁机和禁用锁机一定要是同一个对象,因此建议使用一个不中断的service一直保存这个对象。
否则会导致开禁失效


--------------------------------------------------------------------------------
ps:此处开始与标题内容无关。android  SCREEN OFF & SCREEN ON 需要在程序中注册。

                //注册闭屏广播
                IntentFilter mFilter01;
                mFilter01 = new IntentFilter("android.intent.action.SCREEN_OFF");
                offReceiver = new ScreenOFFReceiver();
                registerReceiver(offReceiver, mFilter01);
               
                //注册开屏广播
                IntentFilter mFilter02;
                mFilter02 = new IntentFilter("android.intent.action.SCREEN_ON");
                onReceiver = new ScreenONReceiver();
                registerReceiver(onReceiver, mFilter02);

               public class ScreenOFFReceiver extends BroadcastReceiver{

        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            Log.d("H3c","screen off");
        }
    }
   
    public class ScreenONReceiver extends BroadcastReceiver{
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d("H3c","screen on");

        }
   

你可能感兴趣的:(Android,H3C)