android中监听home事件

android中,要监听home键的事件,在下只知道用广播来进行监听,下面直接上代码

//在onCreate中进行注册homeKeyEventBroadCastReceiver = new HomeKeyEventBroadCastReceiver(); registerReceiver(homeKeyEventBroadCastReceiver, new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
//在onDestroy中销毁unregisterReceiver(homeKeyEventBroadCastReceiver);

//下面是广播

public class HomeKeyEventBroadCastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if(action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)){ Log.i("home", "点击了home键"); } }}

你可能感兴趣的:(android中监听home事件)