Android4.4.2 system Add a custom button "go"

Source: Internet
Author: User

This article was reproduced from: http://developer.t-firefly.com/thread-251-1-1.html

There are some articles on the internet about the Android system to add custom keys, but mostly for Android2.3 and 4.0 systems, many files have been changed position, these two days I summed up some, write to welcome everyone to communicate and correct:


Android system through the *.kl file to the top of the Linux button, the latest Android4.4 is no longer the default Qwerty.kl file, the generation is FRAMEWORKS/BASE/DATA/KEYBOARDS/GENERIC.KL file, of course, if you define a board-level key value file, or the Rk29-keypad.kl file takes precedence.

    in the3288/DEVICE/ROCKCHIP/RKSDKunder the directoryRK29-KEYPAD.KLthere are definitions of the key values in the file:
    1. Key to the MENU
    2. Key 102 HOME
    3. Key Volume_down
    4. Key Volume_up
    5. Key Powe WAKE
    6. Key 143 NOTIFICATION WAKE
    7. Key 158 Back
    8. Key 212 CAMERA
    9. Key 217 SEARCH
Copy Code

Description:WAKE: When the device is asleep, the device will be woken up and the key event will be sent to the application. wake_dropped: When the device is asleep, the device is woken up and the key event is not sent to the application.

Rising micro-keys are divided into Gpio and ADC two kinds, defined in the/kernel/arch/arm/boot/dts directory of the Firefly-rk3288.dts file:
  1. &ADC {
  2. Status = "Okay";
  3. Key {
  4. Compatible = "Rockchip, key";
  5. Io-channels = <&ADC 1>;
  6. Vol-up-key {
  7. Linux, code = <115>;
  8. Label = "Volume Up";
  9. Rockchip, Adc_value = <1>;
  10. };
  11. Vol-down-key {
  12. Linux, code = <114>;
  13. Label = "Volume Down";
  14. Rockchip, Adc_value = <170>;
  15. };
  16. Power-key {
  17. Gpios = <&gpio0 gpio_a4 gpio_active_low>;
  18. Linux, code = <116>;
  19. label = "Power";
  20. Gpio-key, Wakeup; Has wake-up function
  21. };
  22. Menu-key {
  23. Linux, code = <139>;
  24. Label = "Menu";
  25. Rockchip, Adc_value = <355>;
  26. };
  27. Home-key {
  28. Linux, code = <102>;
  29. label = "Home";
  30. Rockchip, Adc_value = <746>;
  31. };
  32. Back-key {
  33. Linux, code = <158>;
  34. Label = "Back";
  35. Rockchip, Adc_value = <560>;
  36. };
  37. Camera-key {
  38. Linux, code = <212>;
  39. label = "Camera";
  40. Rockchip, Adc_value = <450>;
  41. };
  42. };
Copy the code first in the Linux kernel to add a new key value (of course, no macro definition of direct write values can also), the Web is generally written in the/include/linux/input/input.h file added, the actual 3.10 kernel in/include/uapi/linux/ Input.h file: #defineKEY_RESERVED 0#define key_esc 1#define key_1 2 ... #defineKEY_MY 250

For Android level, after adding the key value in the Rk29-keypad.kl file, you need to modify some files, the system can process, first repair
Change the KeycodeLabels.h file, version 4.4 moves it to the Frameworks/native/include/input directory and adds a key code to the Keycodes array:
static const keycodelabelkeycodes[] = {
...
{ "My_keys", +, {null,0}
Finally, you must end with a null, where the Tv_keymouse_left button is rising micro-add, and then add to the Frameworks/native/include/android/keycode.h file: enum {
Akeycode_unknown = 0,
....
....
Add to
Akeycode_my_keys=250,
The same akeycode_tv_keymouse_left macro is also rising micro added, if you want to add the system key values, you also need to modify the frameworks/base/libs/ui/ Input.java (android4.4 has become frameworks/native/libs/input/input.cpp) file: Boolkeyevent::hasdefaultaction (int32_t KeyCode) {switch (keycode) {case Akeycode_home:case Akeycode_back: ... caseAkeycode_my_keys: Return true;

There are also the following: Boolkeyevent::issystemkey (int32_t keycode) {switch (keycode) {case Akeycode_menu: ... caseAkeycode_my_keys: Return true; } return false;}

Also modify the Frameworks/base/core/java/android/view/keyevent.java file:
public staticfinal int keycode_tv_media_pause = 249;public staticfinal intKeycode_my_keys= 250;private staticfinal int last_keycode = Keycode_my_keys;
Note Be sure to modify Last_keycode, the following populatekeycodesymbolicnames array also needs to be added: Names.append (Keycode_my_keys, "Keycode_my_keys");

Modify Frameworks/base/core/res/res/values/attr.xml file:<!--This enum provides the same keycode values as can is found in {@link android.view.KeyEvent}. --><attrname= "KeyCode" > <enum name= "keycode_unknown" value= "0"/> ... <enumname= "KEYCOD E_tv_media_pause "value=" 249 "/> <enum name="Keycode_my_keys"Value="/></attr>

The/external/webkit/source/webkit/android/plugins/anpkeycodes.h file that was said on the internet has been removed.

The above files are changed after the frameworks/base/api/current.txt also to update, if not updated, you can run MAKEUPDATE-API to update if the new key value is processed, you can get the corresponding keycode to handle it. The handling of keystroke events is generally as follows:
Frameworks/base/policy/src/com/android/internal/policy/impl/phonewindowmanager.java

@Override Public intinterceptkeybeforequeueing (keyevent event, int policyflags, Boolean isscreenon) {... switch (Keyco DE) {case keyevent.keycode_volume_down: ... case keyevent.Keycode_my_keys://Add processing code

Android4.4.2 system Add a custom button "go"

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.