如何屏蔽Home键

 

1.在onCreate 方法里:

    private KeyguardManager mKeyguardManager;
       private KeyguardLock mKeyguardLock;

    mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
         mKeyguardLock = mKeyguardManager.newKeyguardLock("");
         mKeyguardLock.disableKeyguard();

2.在onDestroy方法里:

    mKeyguardLock.reenableKeyguard();


3.重写 onAttachedToWindow()方法

     @Override
    public void onAttachedToWindow() {
        this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
        super.onAttachedToWindow();
    }

4.在清单文件在中加入如下权限:

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


备注:以上方法可以实现屏蔽 home键,但是在有surfaceview情况下surfaceView会出现黑屏。

你可能感兴趣的:(android,service)