@Override public void onAttachedToWindow() { this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); super.onAttachedToWindow(); }
这是API Level 5以后的方式,在android 1.6中不能用
HOME键在PhoneWindowMananger中就被consume掉了,外界屏蔽不了
看一下源码: 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 key return 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 app return true; } }}两个参数 WindowManager.LayoutParams.TYPE_KEYGUARD和 WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG ,重写onAttachedToWindow,以实现屏蔽Home键,但是API 5以上。 1.6只有修改源码framework层,但是不只是对你的app有效了。
Home键貌似无法屏蔽,而且onkeydown函数根本监测不到home键,系统自动处理了。
api level5之前的HOME无法截获,除非去修改源码,如果是在为企业中应用程序的话,修改源码也不是一条可行的解决方法,要么就升级项目的api 等级 ,要么就不管HOME键 。LZ提的第二个问题,在程序卸载后跳到某个界面做用户调查,这个无法实现;在卸载前做用户调查,我有个思路,但也不太可行,使用android的卸载程序卸载应用时会发送广播,接受广播后启动浏览器或跳到Activity; 还有,每一个动作都有输出流,截取输出流,如果发现卸载那个应用包的信息,做处理
@Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
这是API Level 5以后的方式,在android 1.6中不能用
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 key
return 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 app
return true;
}
}}两个参数 WindowManager.LayoutParams.TYPE_KEYGUARD和
WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG ,重写onAttachedToWindow,以实现屏蔽Home键,但是API 5以上。
1.6只有修改源码framework层,但是不只是对你的app有效了。
还有,每一个动作都有输出流,截取输出流,如果发现卸载那个应用包的信息,做处理