AndroidでHome鍵を処理する方法
方法1 onUserLeaveHint
コード下記:
<a href="https://arkgame.com" target="_blank">@Override</a>
protected
void onUserLeaveHint() {
Log.d(“aeon","onUserLeaveHint");
super.onUserLeaveHint();
}
方法2 ACTION_CLOSE_SYSTEM_DIALOGS
コード下記:
//Receiverを新規登録する
HomeKeyEventBroadCastReceiver receiver = new HomeKeyEventBroadCastReceiver();
registerReceiver(receiver, new IntentFilter(
Intent. ACTION_CLOSE_SYSTEM_DIALOGS));
方法3 framework
コード下記
void handleLongPressOnHome() {
if (mLongPressOnHomeBehavior < 0) {
mLongPressOnHomeBehavior
= mContext.getResources().getInteger(R.integer.config_longPressOnHomeBehavior);
if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
mLongPressOnHomeBehavior > LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
}
}
if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
// Eat the longpress so it won’t dismiss the recent apps dialog when
// the user lets go of the home key
mHomeLongPressed = true;
}
if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_DIALOG) {
showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS);
} else
if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
try {
IStatusBarService statusbar = getStatusBarService();
if (statusbar != null) {
statusbar.toggleRecentApps();
}
} catch (RemoteException e) {
Slog.e(TAG, “RemoteException when showing recent apps", e);
// re-acquire status bar service next time it is needed.
mStatusBarService = null;
}
}
}