发送广播 Intent.ACTION_CLOSE_SYSTEM_DIALOGS,开始 Launch Home,根据这点,我们可以监听广播:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
class
InnerRecevier
extends
BroadcastReceiver {
static
final
String SYSTEM_DIALOG_REASON_KEY =
"reason"
;
static
final
String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS =
"globalactions"
;
static
final
String SYSTEM_DIALOG_REASON_RECENT_APPS =
"recentapps"
;
static
final
String SYSTEM_DIALOG_REASON_HOME_KEY =
"homekey"
;
@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_DIALOG_REASON_KEY);
//获取原因
if
(reason !=
null
) {
Lg.i(
"receive action:"
+ action +
",reason:"
+ reason);
if
(mListener !=
null
) {
if
(reason.equals(SYSTEM_DIALOG_REASON_HOME_KEY)) {
// 按 Home
mListener.onHomePressed();
}
else
if
(reason.equals(SYSTEM_DIALOG_REASON_RECENT_APPS)) {
// 长按 Home
mListener.onHomeLongPressed();
}
}
}
}
}
}
|