private static final String SYSTEM_DIALOG_REASON_KEY = "reason";
private static final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
private static final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
private static final String SYSTEM_DIALOG_REASON_LOCK = "lock";
private static final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.i(TAG, "onReceive: action: " + action);
if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
// android.intent.action.CLOSE_SYSTEM_DIALOGS == action
String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
if (SYSTEM_DIALOG_REASON_HOME_KEY.equals(reason)) {
// 短按 Home 键
Log.i(TAG, "reason: homekey");
} else if (SYSTEM_DIALOG_REASON_RECENT_APPS.equals(reason)) {
// 长按 Home 键或者 Recent 键
Log.i(TAG, "reason: recentapps");
} else if (SYSTEM_DIALOG_REASON_LOCK.equals(reason)) {
// 锁屏
Log.i(TAG, "reason: lock");
} else if (SYSTEM_DIALOG_REASON_ASSIST.equals(reason)) {
// Samsung 长按 Home 键
Log.i(TAG, "reason: assist");
} else {
Log.i(TAG, "reason: " + reason);
}
}
}
};
private IntentFilter mIntentFilter;
mIntentFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
registerReceiver(mBroadcastReceiver, mIntentFilter);
if (null != mBroadcastReceiver) {
unregisterReceiver(mBroadcastReceiver);
}
Android 监听 Home 键
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- Android Home键监听 Android 普通键值可以直接在dispatchKeyEvent()中处理,但H...