Android监听Home键

AndroidBroadcastReceiver大约 761 字

监听Home键广播

不能改reason,homekey这些字符串变量的值

private BroadcastReceiver homeListenerReceiver = new BroadcastReceiver() {
    String SYSTEM_DIALOG_REASON_KEY = "reason";
    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 && reason.equals(SYSTEM_DIALOG_REASON_HOME_KEY)) {
                hide();
            }
        }
    }
};
IntentFilter homeFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
mContext.registerReceiver(homeListenerReceiver, homeFilter);
阅读 372 · 发布于 2019-04-09

————        END        ————

扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看换一批