1.屏蔽返回键
@Override
public void onBackPressed() {
// super.onBackPressed();
}
2.屏蔽Home键
首先需要在onCreate()里面注册广播:
registerReceiver(mHomeKeyEventReceiver, new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
然后监听mHomeKeyEventReceiver这个广播:
private BroadcastReceiver mHomeKeyEventReceiver = new BroadcastReceiver() {
String SYSTEM_REASON = "reason";
String SYSTEM_HOME_KEY = "homekey";
String SYSTEM_HOME_KEY_LONG = "recentapps";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) { // 监听home键
String reason = intent.getStringExtra(SYSTEM_REASON);
// 表示按了home键,程序到了后台
}
}
};