• 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...");
                    }
                }
            }
        }

    }

  • 相关阅读:
    javascript基础01
    javascript基础02
    javascript基础03
    javascript基础04
    javascript基础05
    javascript基础06
    Android 实现截屏功能
    android 获取摄像头像素
    c# Winform dataGridView动态添加行
    Android 读取Assets下的文件
  • 原文地址:https://www.cnblogs.com/lianghui66/p/3222735.html
Copyright © 2020-2023  润新知