發送廣播 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(); } } } } } } |