KeyMapManager

##
android.device
Class KeyMapManager

    java.lang.Object
      android.device.KeyMapManager

    public class KeyMapManager

extends java.lang.Object

KeyMapManager class used to remap key and button events. The mapped keys can start the application, send the broadcast and other key functions. Mapping is still valid after reboot. Note that this class only works on Android 5.1 and Android 4.3 and later.

Use this class to control the basic functions of the equipment system, according to the following steps,

1. You should define a class parameter at first.

   import android.device.KeyMapManager;

2. Then, you can obtain an instance of this class by calling KeyMapManager.

   KeyMapManager mKeyMap = new KeyMapManager(Android.content.Context context);

3. Before starting the call, you can judge whether the system enables mapping through `isInterception` and enable mapping through `disableInterception`.

   For more information about remap key, read KeyMapManager sample.

Nested Class Summary
`class` | `KeyMapManager.KeyEntry` Describes the keys provided by button event and their associated labels.

Field Summary
`static int` | `KEY_TYPE_KEYCODE` This mask is used to remap new keycode FUNCTION.
`static int` | `KEY_TYPE_STARTAC` This mask is used to remap special actions to start APPS FUNCTION.

Constructor Summary
`KeyMapManager(Android.content.Context context)` The KeyMapManager class used to remap key and button events.

Method Summary
`void` | `delKeyEntry(int scancode)` Delete the Button key remap.
`void` | `disableInterception(boolean interception)` Disable or enable system remap Button key event.
`java.lang.String` | `getKeyAction(int scancode)` Get special actions if this scan code is a KeyEvent keycode. Only supports Android 7.1.
`int` | `getKeyCode(int scancode)` Get new keycode if this scan code is a KeyEvent keycode.
`java.util.List<KeyMapManager.KeyEntry>` | `getKeyList()` Get all remap keys describes.
`int` | `getKeyMeta(int scancode)` Get new keycode after remap if this scan code is a KeyEvent keycode.
`int` | `getKeyType(int scancode)` Get ramap type if this scan code is a KeyEvent keycode.
`boolean` | `hasKeyEntry(int scancode)` Judge the Button key remap state.
`boolean` | `isInterception()` True if enable system remap Button key event.
`void` | `mapKeyEntry(KeyEvent event, int keyType, java.lang.String meta)` Create a new key event remap that is the same as the given one, but whose keycode is replaced with the given value.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

FIELD DETAIL

### KEY_TYPE_KEYCODE

    public static final int KEY_TYPE_KEYCODE

  This mask is used to remap new keycode FUNCTION.

  See Also:
    Constant Field Values

### KEY_TYPE_STARTAC

    public static final int KEY_TYPE_STARTAC

  This mask is used to remap special actions to start APPS FUNCTION.

  See Also:
    Constant Field Values

Constructor Detail

### KeyMapManager

    public KeyMapManager(Android.content.Context context)

Method Detail

### hasKeyEntry

    public boolean hasKeyEntry(int scancode)

  Judge the Button key remap state.

  Parameters:
    `scancode` - `android.view.KeyEvent#getScanCode()`
  Returns:
    true if the Button key is remap, false otherwise.
  Example:
    `KeyMapManager mKeyMap = new KeyMapManager();
    if (mKeyMap.hasKeyEntry(event.getScanCode())) {
    //Button key is remap
    }`

### delKeyEntry

    public void delKeyEntry(int scancode)

  Delete the Button key remap.

  Parameters:
    `scancode` - `android.view.KeyEvent#getScanCode()`
  Returns:
    none
  Example:
    `KeyMapManager mKeyMap = new KeyMapManager();
    mKeyMap.delKeyEntry(event.getScanCode());`

### mapKeyEntry

    public void mapKeyEntry(KeyEvent event,
                            int keyType,
                            java.lang.String meta)

  Create a new key event remap that is the same as the given one, but whose keycode is replaced with the given value.

  Parameters:
    `event` - The button key event `android.view.KeyEvent`.
    `keyType` - The key type. See `KEY_TYPE_KEYCODE` or `KEY_TYPE_STARTAC`.
    `meta` - New keycode or special actions to start APPS `android.content.Intent`.
  Returns:
    none

### isInterception

    public boolean isInterception()

  True if enable system remap Button key event.

  Parameters:
    none
  Returns:
    True if the remap function is enable, false otherwise.
  Example:
    `KeyMapManager mKeyMap = new KeyMapManager();
    if (mKeyMap.isInterception()) {
    //remap function
    }`

### disableInterception

    public void disableInterception(boolean interception)

  Disable or enable system remap button key event.

  Parameters:
    `interception` - True disable remap KeyEvent, false otherwise.
  Returns:
    none
  Example:
    `KeyMapManager mKeyMap = new KeyMapManager();`
    //enable system remap button key events
    `mKeyMap.disableInterception(false);`
    //disable system remap button key events
    `mKeyMap.disableInterception(true);`

### getKeyCode

    public int getKeyCode(int scancode)

  Get new keycode if this scan code is a KeyEvent keycode.

  Parameters:
    `scancode` - `android.view.KeyEvent#getScanCode()`
  Returns:
    the keycode or -1 if not found.

### getKeyMeta

    public int getKeyMeta(int scancode)

  Get new keycode after remap if this scan code is a KeyEvent keycode.

  Parameters:
    `scancode` - `android.view.KeyEvent#getScanCode()`
  Returns:
    the keycode or -1 if not found.

### getKeyAction

    public java.lang.String getKeyAction(int scancode)

  Get special actions if this scan code is a KeyEvent keycode. Only supports Android 7.1.

  Parameters:
    `scancode` - `android.view.KeyEvent#getScanCode()`
  Returns:
    Special actions to start APPS `android.content.Intent`, null otherwise.

### getKeyType

    public int getKeyType(int scancode)

  Get ramap type if this scan code is a KeyEvent keycode.

  Parameters:
    `scancode` - `android.view.KeyEvent#getScanCode()`
  Returns:
    The Key type. See `KEY_TYPE_KEYCODE` or `KEY_TYPE_STARTAC`, -1 otherwise.

### getKeyList

    public java.util.List<KeyMapManager.KeyEntry> getKeyList()

  Get all remap keys describes.

  Parameters:
    none
  Returns:
    Describes list `KeyMapManager.KeyEntry`, null otherwise.