Google is committed to advancing racial equity for Black communities. See how.
Added in API level 16

InputManager

class InputManager
kotlin.Any
   ↳ android.hardware.input.InputManager

Provides information about input devices and available key layouts.

Summary

Nested classes

abstract

Listens for changes in input devices.

Constants

static String

Broadcast Action: Query available keyboard layouts.

static String

Metadata Key: Keyboard layout metadata associated with ACTION_QUERY_KEYBOARD_LAYOUTS.

Public methods

InputDevice!

Gets information about the input device with the specified id.

IntArray!

Gets the ids of all input devices in the system.

Unit

Registers an input device listener to receive notifications about when input devices are added, removed or changed.

Unit

Unregisters an input device listener.

VerifiedInputEvent?

Verify the details of an android.view.InputEvent that came from the system.

Constants

ACTION_QUERY_KEYBOARD_LAYOUTS

Added in API level 16
static val ACTION_QUERY_KEYBOARD_LAYOUTS: String

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.

<code>
  &lt;receiver android:name=".InputDeviceReceiver"
          android:label="@string/keyboard_layouts_label"&gt;
      &lt;intent-filter&gt;
          &lt;action android:name="android.hardware.input.action.QUERY_KEYBOARD_LAYOUTS" /&gt;
      &lt;/intent-filter&gt;
      &lt;meta-data android:name="android.hardware.input.metadata.KEYBOARD_LAYOUTS"
              android:resource="@xml/keyboard_layouts" /&gt;
  &lt;/receiver&gt;
  </code>

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.

<code>
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;keyboard-layouts xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;keyboard-layout android:name="keyboard_layout_english_us"
              android:label="@string/keyboard_layout_english_us_label"
              android:keyboardLayout="@raw/keyboard_layout_english_us" /&gt;
  &lt;/keyboard-layouts&gt;
  </code>

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.

Value: "android.hardware.input.action.QUERY_KEYBOARD_LAYOUTS"

META_DATA_KEYBOARD_LAYOUTS

Added in API level 16
static val META_DATA_KEYBOARD_LAYOUTS: String

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.

Value: "android.hardware.input.metadata.KEYBOARD_LAYOUTS"

Public methods

getInputDevice

Added in API level 16
fun getInputDevice(id: Int): InputDevice!

Gets information about the input device with the specified id.

Parameters
id Int: The device id.
Return
InputDevice! The input device or null if not found.

getInputDeviceIds

Added in API level 16
fun getInputDeviceIds(): IntArray!

Gets the ids of all input devices in the system.

Return
IntArray! The input device ids.

registerInputDeviceListener

Added in API level 16
fun registerInputDeviceListener(
    listener: InputManager.InputDeviceListener!,
    handler: Handler!
): Unit

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.

unregisterInputDeviceListener

Added in API level 16
fun unregisterInputDeviceListener(listener: InputManager.InputDeviceListener!): Unit

Unregisters an input device listener.

Parameters
listener InputManager.InputDeviceListener!: The listener to unregister.

verifyInputEvent

Added in API level 30
fun verifyInputEvent(event: InputEvent): VerifiedInputEvent?

Verify the details of an android.view.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 android.view.InputEvent to check This value cannot be null.
Return
VerifiedInputEvent? android.view.VerifiedInputEvent, which is a subset of the provided android.view.InputEvent null if the event could not be verified.