java.lang.Objectandroid.device.KeyMapManager
public class KeyMapManager
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,
import android.device.KeyMapManager;
KeyMapManager mKeyMap = new KeyMapManager(Android.content.Context context);
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 |
public static final int KEY_TYPE_KEYCODE
This mask is used to remap new keycode FUNCTION.
public static final int KEY_TYPE_STARTAC
This mask is used to remap special actions to start APPS FUNCTION.
public KeyMapManager(Android.content.Context context)
public boolean hasKeyEntry(int scancode)
Judge the Button key remap state.
scancode
- android.view.KeyEvent#getScanCode()
KeyMapManager mKeyMap = new KeyMapManager();
if (mKeyMap.hasKeyEntry(event.getScanCode())) {
//Button key is remap
}
public void delKeyEntry(int scancode)
Delete the Button key remap.
scancode
- android.view.KeyEvent#getScanCode()
KeyMapManager mKeyMap = new KeyMapManager();
mKeyMap.delKeyEntry(event.getScanCode());
public void mapKeyEntry(KeyEvent event, int keyType, java.lang.String meta)
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
.
public boolean isInterception()
KeyMapManager mKeyMap = new KeyMapManager();
if (mKeyMap.isInterception()) {
//remap function
}
public void disableInterception(boolean interception)
interception
- True disable remap KeyEvent, false otherwise.
KeyMapManager mKeyMap = new KeyMapManager();
mKeyMap.disableInterception(false);
mKeyMap.disableInterception(true);
public int getKeyCode(int scancode)
scancode
- android.view.KeyEvent#getScanCode()
public int getKeyMeta(int scancode)
scancode
- android.view.KeyEvent#getScanCode()
public java.lang.String getKeyAction(int scancode)
scancode
- android.view.KeyEvent#getScanCode()
android.content.Intent
, null otherwise.public int getKeyType(int scancode)
scancode
- android.view.KeyEvent#getScanCode()
KEY_TYPE_KEYCODE
or KEY_TYPE_STARTAC
, -1 otherwise.public java.util.List<KeyMapManager.KeyEntry> getKeyList()
KeyMapManager.KeyEntry
, null otherwise.