android屏蔽HOME键的方法

在相应的Activity中加入:

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

下面是FRAMWORK层的代码,里面的type == WindowManager.LayoutParams.TYPE_KEYGUARD条件是返回FALSE

if (code == KeyEvent.KEYCODE_HOME) {// If a system window has focus, then it doesn't make sense// right now to interact with applications.WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;if (attrs != null) {final int type = attrs.type;if (type == WindowManager.LayoutParams.TYPE_KEYGUARD|| type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {// the "app" is keyguard, so give it the keyreturn false;}final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;for (int i=0; i<typeCount; i++) {if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {// don't do anything, but also don't pass it to the appreturn true;}}} 


本文链接:https://my.lmcjl.com/post/12996.html

展开阅读全文

4 评论

留下您的评论.