Home键监听
编写广播接收器
编写广播接收器
private final BroadcastReceiver homePressReceiver = new BroadcastReceiver() {
final String SYSTEM_DIALOG_REASON_KEY = "reason";
final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
if(reason != null
&& reason.equals(SYSTEM_DIALOG_REASON_HOME_KEY)) {
// 自己随意控制程序,关闭...
}
}
}
在onCreate中注册接收器
final IntentFilter homeFilter = new IntentFilter(
Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
registerR