Android监听home键

亦余心之所善兮,虽九死其犹未悔。这篇文章主要讲述Android监听home键相关的知识,希望能为你提供帮助。

/** * * 监听Home键 */ 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)) { String reason = intent.getStringExtra(SYSTEM_REASON); if (TextUtils.equals(reason, SYSTEM_HOME_KEY)) { //表示按了home键,程序到了后台 AppConfigManager.getInstance().setLastIsPlayFlag((mFgPlayer != null) ? mFgPlayer.isPlaying() : false); }else if(TextUtils.equals(reason, SYSTEM_HOME_KEY_LONG)){ //表示长按home键,显示最近使用的程序列表 } } } };

记得注册广播:
registerReceiver(mHomeKeyEventReceiver, new IntentFilter( Intent.ACTION_CLOSE_SYSTEM_DIALOGS));

【Android监听home键】

    推荐阅读