• MTK 自定义按键添加广播


    一、给自定义按键添加广播

    修改PhoneWindowManager.java中的interceptKeyBeforeDispatching方法

    /frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

    @Override
      public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
        final boolean keyguardOn = keyguardOn();
        final int keyCode = event.getKeyCode();
        final int repeatCount = event.getRepeatCount();
        final int metaState = event.getMetaState();
        final int flags = event.getFlags();
        final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
        final boolean canceled = event.isCanceled();
        final boolean longPress = (flags & KeyEvent.FLAG_LONG_PRESS) != 0;
        final boolean virtualKey = event.getDeviceId() == KeyCharacterMap.VIRTUAL_KEYBOARD;
        final String isCitKeyTest=SystemProperties.get("persist.sys.startCitKeyTest");
     
     
         
        //添加自定义按键广播----开始
        switch (keyCode)
          {
            case 135:
            case 136:
            case 137:
            case 139:
            {
              if (repeatCount == 0) {
                 
                Intent myKeyIntent = new Intent();
                 
                 
                if(down)
                {
                  myKeyIntent.setAction("com.rscja.android.KEY_DOWN");
                }
                else
                {
                  myKeyIntent.setAction("com.rscja.android.KEY_UP");
                }
                 
               
                myKeyIntent.putExtra("keycode", keyCode);
                 
                mContext.sendBroadcastAsUser(myKeyIntent, UserHandle.ALL); 
                 
                 
               
              }
            }
             
             
             
              break;
          }
           
          //添加自定义按键广播----结束
            // myron add robot wakeup key
            if (keyCode == 0) {
                Intent myronIntent = new Intent();
                if(down) {
                    myronIntent.setAction("com.yxrobot.KEY_DOWN");
                } else {
                    myronIntent.setAction("com.yxrobo.KEY_UP")
                }
                myronIntent.putExtra("keycode", keycode);
                mContext.sendBroadcastAsUser(myronIntent, UserHandle, ALL);
            }
  • 相关阅读:
    外卖 CPS
    拼多多虚拟产品搬砖玩法
    搞笑表情包
    读书
    抖音跑步赚钱
    bootstrapTable固定表头,表头错位问题
    关闭离开页面浏览器提示"确实要离开吗"
    子页面如何调用/关闭父页面layer
    BootstrapValidator 解决多属性被同时校验问题
    使用备份文件新建数据库Web框架
  • 原文地址:https://www.cnblogs.com/zxouxuewei/p/8259718.html
Copyright © 2020-2023  润新知