Android APIs
public final class

InputManager

extends Object
java.lang.Object
   ↳ android.hardware.input.InputManager

Class Overview

Provides information about input devices and available key layouts.

Get an instance of this class by calling Context.getSystemService() with the argument INPUT_SERVICE.

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 ACTION_QUERY_KEYBOARD_LAYOUTS.
Public Methods
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.
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 unregisterInputDeviceListener(InputManager.InputDeviceListener listener)
Unregisters an input device listener.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String ACTION_QUERY_KEYBOARD_LAYOUTS

Added in API level 16

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 attributes 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.

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

public static final String META_DATA_KEYBOARD_LAYOUTS

Added in API level 16

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

public InputDevice getInputDevice (int id)

Added in API level 16

Gets information about the input device with the specified id.

Parameters
id The device id.
Returns
  • The input device or null if not found.

public int[] getInputDeviceIds ()

Added in API level 16

Gets the ids of all input devices in the system.

Returns
  • The input device ids.

public void registerInputDeviceListener (InputManager.InputDeviceListener listener, Handler handler)

Added in API level 16

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

Parameters
listener The listener to register.
handler The handler on which the listener should be invoked, or null if the listener should be invoked on the calling thread's looper.

public void unregisterInputDeviceListener (InputManager.InputDeviceListener listener)

Added in API level 16

Unregisters an input device listener.

Parameters
listener The listener to unregister.