zoukankan      html  css  js  c++  java
  • android 监听Home键

    /**
     * Home 键监听,当按下Home键时,系统会发出action为Intent.ACTION_CLOSE_SYSTEM_DIALOGS的BroadcastReceiver
     * 在程序里动态注册监听,即可达到监听Home键的效果
     */
    public class InnerReceiver extends BroadcastReceiver {

        final String SYSTEM_DIALOG_REASON_KEY = "reason";
        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 (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
                String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
                if (reason != null) {
                    Log.e("TAB", "action:" + action + ",reason:" + reason);
                    if (reason.equals(SYSTEM_DIALOG_REASON_HOME_KEY)) {
                        // 短按home键
                        Log.e("TAB", "home key down....");
                    } else if (reason.equals(SYSTEM_DIALOG_REASON_RECENT_APPS)) {
                        // 长按home键
                        Log.e("TAB", "home long key down...");
                    }
                }
            }
        }

    }

  • 相关阅读:
    20162328蔡文琛 四则运算第一周
    实验三:实验报告
    20162328蔡文琛week09
    20162328蔡文琛week08
    20162328蔡文琛week07
    实验报告二
    20162312张家铖 10.9查找课堂测试
    20162312实验一
    # 20162312 2017-2018-3 《程序设计与数据结构》第3周学习总结
    # 20162312 2017-2018-1 《程序设计与数据结构》第1周学习总结
  • 原文地址:https://www.cnblogs.com/lianghui66/p/3222735.html
Copyright © 2011-2022 走看看