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);
}
网友评论