Android给自定义按键添加广播和通过广播给当前焦点输入框赋值
程序员文章站
2024-03-02 20:15:10
一、给自定义按键添加广播
修改phonewindowmanager.java中的interceptkeybeforedispatching方法
/frameworks/...
一、给自定义按键添加广播
修改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; } //添加自定义按键广播----结束 …… …… …… …… }
二、通过广播给当前焦点输入框赋值
修改inputmethodservice.java中的oncreate()方法
/frameworks/base/core/java/android/inputmethodservice/inputmethodservice.java
感谢阅读,希望能帮助到大家,谢谢大家对本站的 支持!
上一篇: 0014---简单的计算
下一篇: Java中的大数类简单实现