InputManager
public
final
class
InputManager
extends Object
| java.lang.Object | |
| ↳ | android.hardware.input.InputManager |
Provides information about input devices and available key layouts.
Summary
Nested classes | |
|---|---|
interface |
InputManager.InputDeviceListener
Listens for changes in input devices. |
Constants | |
|---|---|
String |
ACTION_QUERY_KEYBOARD_LAYOUTS
Broadcast Action: Query available keyboard layouts. |
String |
META_DATA_KEYBOARD_LAYOUTS
Metadata Key: Keyboard layout metadata associated with
|
Public methods | |
|---|---|
void
|
addPeripheralCustomization(int vendorId, int productId, CustomizationTrigger trigger, CustomizationAction action)
Adds a new peripheral customization for a given vendor ID and product ID. |
Map<CustomizationTrigger, CustomizationAction>
|
getAllPeripheralCustomizations(int vendorId, int productId)
Retrieves all input customizations for a specific peripheral device. |
HostUsiVersion
|
getHostUsiVersion(Display display)
Reports the version of the Universal Stylus Initiative (USI) protocol supported by the given display, if any. |
InputDevice
|
getInputDevice(int id)
Gets information about the input device with the specified id. |
int[]
|
getInputDeviceIds()
Gets the ids of all input devices in the system. |
InputDevice.ViewBehavior
|
getInputDeviceViewBehavior(int deviceId)
Gets the |
float
|
getMaximumObscuringOpacityForTouch()
Returns the maximum allowed obscuring opacity per UID to propagate touches. |
CustomizationAction
|
getPeripheralCustomization(int vendorId, int productId, CustomizationTrigger trigger)
Retrieves a specific peripheral customization action for a given trigger. |
boolean
|
isButtonAllowedForCustomization(int vendorId, int productId, int buttonCode)
Checks if a specific button is allowed for customization on the device(s). |
boolean
|
isKeyAllowedForCustomization(int vendorId, int productId, int keyCode)
Gets whether a keycode can be customized on a device. |
boolean
|
isStylusPointerIconEnabled()
Check if showing a |
void
|
registerInputDeviceListener(InputManager.InputDeviceListener listener, Handler handler)
Registers an input device listener to receive notifications about when input devices are added, removed or changed. |
void
|
removeAllPeripheralCustomizations(int vendorId, int productId)
Remove all peripheral customizations for a given vendor ID and product ID. |
void
|
removePeripheralCustomization(int vendorId, int productId, CustomizationTrigger trigger)
Removes a peripheral customization for a given vendor ID and product ID. |
void
|
unregisterInputDeviceListener(InputManager.InputDeviceListener listener)
Unregisters an input device listener. |
VerifiedInputEvent
|
verifyInputEvent(InputEvent event)
Verify the details of an |
Inherited methods | |
|---|---|
Constants
ACTION_QUERY_KEYBOARD_LAYOUTS
public static final String ACTION_QUERY_KEYBOARD_LAYOUTS
Broadcast Action: Query available keyboard layouts.
The input manager service locates available keyboard layouts by querying broadcast receivers that are registered for this action. An application can offer additional keyboard layouts to the user by declaring a suitable broadcast receiver in its manifest.
Here is an example broadcast receiver declaration that an application might include in its AndroidManifest.xml to advertise keyboard layouts. The meta-data specifies a resource that contains a description of each keyboard layout that is provided by the application.
<receiver android:name=".InputDeviceReceiver"
android:label="@string/keyboard_layouts_label">
<intent-filter>
<action android:name="android.hardware.input.action.QUERY_KEYBOARD_LAYOUTS" />
</intent-filter>
<meta-data android:name="android.hardware.input.metadata.KEYBOARD_LAYOUTS"
android:resource="@xml/keyboard_layouts" />
</receiver>
In the above example, the @xml/keyboard_layouts resource refers to
an XML resource whose root element is <keyboard-layouts> that
contains zero or more <keyboard-layout> elements.
Each <keyboard-layout> element specifies the name, label, and location
of a key character map for a particular keyboard layout. The label on the receiver
is used to name the collection of keyboard layouts provided by this receiver in the
keyboard layout settings.
<?xml version="1.0" encoding="utf-8"?>
<keyboard-layouts xmlns:android="http://schemas.android.com/apk/res/android">
<keyboard-layout android:name="keyboard_layout_english_us"
android:label="@string/keyboard_layout_english_us_label"
android:keyboardLayout="@raw/keyboard_layout_english_us" />
</keyboard-layouts>
The android:name attribute specifies an identifier by which
the keyboard layout will be known in the package.
The android:label attribute specifies a human-readable descriptive
label to describe the keyboard layout in the user interface, such as "English (US)".
The android:keyboardLayout attribute refers to a
key character map resource that defines the keyboard layout.
The android:keyboardLocale attribute specifies a comma separated list of BCP 47
language tags depicting the locales supported by the keyboard layout. This attribute is
optional and will be used for auto layout selection for external physical keyboards.
The android:keyboardLayoutType attribute specifies the layoutType for the
keyboard layout. This can be either empty or one of the following supported layout types:
qwerty, qwertz, azerty, dvorak, colemak, workman, extended, turkish_q, turkish_f. This
attribute is optional and will be used for auto layout selection for external physical
keyboards.
Constant Value: "android.hardware.input.action.QUERY_KEYBOARD_LAYOUTS"
META_DATA_KEYBOARD_LAYOUTS
public static final String META_DATA_KEYBOARD_LAYOUTS
Metadata Key: Keyboard layout metadata associated with
ACTION_QUERY_KEYBOARD_LAYOUTS.
Specifies the resource id of a XML resource that describes the keyboard layouts that are provided by the application.
Constant Value: "android.hardware.input.metadata.KEYBOARD_LAYOUTS"
Public methods
addPeripheralCustomization
public void addPeripheralCustomization (int vendorId,
int productId,
CustomizationTrigger trigger,
CustomizationAction action)Adds a new peripheral customization for a given vendor ID and product ID.
This will remap a key on all connected peripheral devices matching the vendor and product ID
to a different action.
Requires Manifest.permission.MANAGE_PERIPHERAL_CUSTOMIZATION
| Parameters | |
|---|---|
vendorId |
int: the vendor ID of the device |
productId |
int: the product ID of the device |
trigger |
CustomizationTrigger: the trigger for the customization.
This value cannot be null. |
action |
CustomizationAction: the action to be executed by the trigger.
This value cannot be null. |
| Throws | |
|---|---|
IllegalArgumentException |
if the CustomizationTrigger or
CustomizationAction is unsupported. |
IllegalStateException |
if no device with vendorId and productId is
connected. |
getAllPeripheralCustomizations
public Map<CustomizationTrigger, CustomizationAction> getAllPeripheralCustomizations (int vendorId, int productId)
Retrieves all input customizations for a specific peripheral device.
Requires Manifest.permission.MANAGE_PERIPHERAL_CUSTOMIZATION
| Parameters | |
|---|---|
vendorId |
int: the vendor ID of the device |
productId |
int: the product ID of the device |
| Returns | |
|---|---|
Map<CustomizationTrigger, CustomizationAction> |
A map of triggers to actions, or an empty map if none exists.
This value cannot be null. |
| Throws | |
|---|---|
IllegalStateException |
if no device with vendorId and productId is
connected. |
getHostUsiVersion
public HostUsiVersion getHostUsiVersion (Display display)
Reports the version of the Universal Stylus Initiative (USI) protocol supported by the given display, if any.
| Parameters | |
|---|---|
display |
Display: This value cannot be null. |
| Returns | |
|---|---|
HostUsiVersion |
the USI version supported by the display, or null if the device does not support USI |
See also:
getInputDevice
public InputDevice getInputDevice (int id)
Gets information about the input device with the specified id.
| Parameters | |
|---|---|
id |
int: The device id. |
| Returns | |
|---|---|
InputDevice |
The input device or null if not found. |
getInputDeviceIds
public int[] getInputDeviceIds ()
Gets the ids of all input devices in the system.
| Returns | |
|---|---|
int[] |
The input device ids. |
getInputDeviceViewBehavior
public InputDevice.ViewBehavior getInputDeviceViewBehavior (int deviceId)
Gets the InputDevice.ViewBehavior of the input device with a given id.
Use this API to query a fresh view behavior instance whenever the input device changes.
| Parameters | |
|---|---|
deviceId |
int: the id of the input device whose view behavior is being requested. |
| Returns | |
|---|---|
InputDevice.ViewBehavior |
the view behavior of the input device with the provided id, or null if there
is not input device with the provided id. |
getMaximumObscuringOpacityForTouch
public float getMaximumObscuringOpacityForTouch ()
Returns the maximum allowed obscuring opacity per UID to propagate touches.
For certain window types (eg. LayoutParams.TYPE_APPLICATION_OVERLAY), the decision
of honoring LayoutParams.FLAG_NOT_TOUCHABLE or not depends on the combined obscuring
opacity of the windows above the touch-consuming window, per UID. Check documentation of
LayoutParams.FLAG_NOT_TOUCHABLE for more details.
The value returned is between 0 (inclusive) and 1 (inclusive).
| Returns | |
|---|---|
float |
Value is between 0.0f and 1.0f inclusive |
See also:
getPeripheralCustomization
public CustomizationAction getPeripheralCustomization (int vendorId, int productId, CustomizationTrigger trigger)
Retrieves a specific peripheral customization action for a given trigger.
Requires Manifest.permission.MANAGE_PERIPHERAL_CUSTOMIZATION
| Parameters | |
|---|---|
vendorId |
int: the vendor ID of the device |
productId |
int: the product ID of the device |
trigger |
CustomizationTrigger: This value cannot be null. |
| Returns | |
|---|---|
CustomizationAction |
action or null if none exists. |
| Throws | |
|---|---|
IllegalStateException |
if no device with vendorId and productId is
connected. |
isButtonAllowedForCustomization
public boolean isButtonAllowedForCustomization (int vendorId,
int productId,
int buttonCode)Checks if a specific button is allowed for customization on the device(s).
Requires Manifest.permission.MANAGE_PERIPHERAL_CUSTOMIZATION
| Parameters | |
|---|---|
vendorId |
int: the vendor ID of the device. |
productId |
int: the product ID of the device. |
buttonCode |
int: the button code to check.
Value is one of the following:
|
| Returns | |
|---|---|
boolean |
true if the button can be customized on the matching devices, False otherwise. |
| Throws | |
|---|---|
IllegalStateException |
if no device with vendorId and productId is
connected. |
isKeyAllowedForCustomization
public boolean isKeyAllowedForCustomization (int vendorId,
int productId,
int keyCode)Gets whether a keycode can be customized on a device.
Requires Manifest.permission.MANAGE_PERIPHERAL_CUSTOMIZATION
| Returns | |
|---|---|
boolean |
true if the keycode can be customized on the device. False otherwise. |
| Throws | |
|---|---|
IllegalStateException |
if no device with vendorId and productId is
connected. |
isStylusPointerIconEnabled
public boolean isStylusPointerIconEnabled ()
Check if showing a PointerIcon for styluses is enabled.
| Returns | |
|---|---|
boolean |
true if a pointer icon will be shown over the location of a stylus pointer, false if there is no pointer icon shown for styluses. |
registerInputDeviceListener
public void registerInputDeviceListener (InputManager.InputDeviceListener listener, Handler handler)
Registers an input device listener to receive notifications about when input devices are added, removed or changed.
| Parameters | |
|---|---|
listener |
InputManager.InputDeviceListener: The listener to register. |
handler |
Handler: The handler on which the listener should be invoked, or null
if the listener should be invoked on the calling thread's looper. |
removeAllPeripheralCustomizations
public void removeAllPeripheralCustomizations (int vendorId,
int productId)Remove all peripheral customizations for a given vendor ID and product ID.
This will remove all customizations on all connected peripheral devices matching the
vendor and product ID. If no customizations exist, this method does nothing.
Requires Manifest.permission.MANAGE_PERIPHERAL_CUSTOMIZATION
| Parameters | |
|---|---|
vendorId |
int: the vendor ID of the device |
productId |
int: the product ID of the device |
removePeripheralCustomization
public void removePeripheralCustomization (int vendorId,
int productId,
CustomizationTrigger trigger)Removes a peripheral customization for a given vendor ID and product ID.
This will remove a specific customization on all connected peripheral devices matching the
vendor and product ID. If the specified customization does not exist,
this method does nothing.
Requires Manifest.permission.MANAGE_PERIPHERAL_CUSTOMIZATION
| Parameters | |
|---|---|
vendorId |
int: the vendor ID of the device |
productId |
int: the product ID of the device |
trigger |
CustomizationTrigger: the trigger of the customization to remove.
This value cannot be null. |
unregisterInputDeviceListener
public void unregisterInputDeviceListener (InputManager.InputDeviceListener listener)
Unregisters an input device listener.
| Parameters | |
|---|---|
listener |
InputManager.InputDeviceListener: The listener to unregister. |
verifyInputEvent
public VerifiedInputEvent verifyInputEvent (InputEvent event)
Verify the details of an InputEvent that came from the system.
If the event did not come from the system, or its details could not be verified, then this
will return null. Receiving null does not mean that the event did not
originate from the system, just that we were unable to verify it. This can
happen for a number of reasons during normal operation.
| Parameters | |
|---|---|
event |
InputEvent: The InputEvent to check.
This value cannot be null. |
| Returns | |
|---|---|
VerifiedInputEvent |
VerifiedInputEvent, which is a subset of the provided
InputEvent, or null if the event could not be verified. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2026-06-23 UTC.