监听HOME广播

class InnerRecevier extends BroadcastReceiver {
 
        final String SYSTEM_DIALOG_REASON_KEY = "reason";
 
        final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
 
        final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
 
        final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
 
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
                String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
                if (reason != null) {
                    if (reason.equals(SYSTEM_DIALOG_REASON_HOME_KEY)) {
                        //press home
                    } else if (reason.equals(SYSTEM_DIALOG_REASON_RECENT_APPS)) {
                        //long press home
                    }
                }
            }
        }
    }

你可能感兴趣的:(监听HOME广播)