Android adds a broadcast to the custom key and assigns a value to the current focus input box by broadcasting _android

Source: Internet
Author: User

First, add a broadcast to the custom key

Modifying the Interceptkeybeforedispatching method in Phonewindowmanager.java

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

@Override Public long interceptkeybeforedispatching (WindowState win, keyevent event, int policyflags) {final Boole
    An 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");
        Add a custom key broadcast----start 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; ///Add custom key to broadcast----end ..............}

Assigning values to the current focus input box by broadcasting

Modifying the OnCreate () method in Inputmethodservice.java

/frameworks/base/core/java/android/inputmethodservice/inputmethodservice.java

Thank you for reading, I hope to help you, thank you for your support for this site!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.