Added in [version 37.1](https://developer.android.com/topic/libraries/support-library/revisions) Summary: [Methods](https://developer.android.com/reference/android/hardware/hid/HidManager#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/hardware/hid/HidManager#inhmethods)

# HidManager

*** ** * ** ***


`
public

final

class
HidManager
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.hardware.hid.HidManager |

<br />

*** ** * ** ***

Provides access to Human Interface Device (HID) nodes.

This manager allows applications to enumerate connected HID devices and query their
information (such as vendor/product IDs and report descriptors).

HID devices include peripherals such as keyboards, mice, game controllers, and other
interactive devices that follow the HID specification.

Access to HID devices requires the `https://developer.android.com/reference/android/Manifest.permission#ACCESS_HID` permission.
Apps are typically granted access to specific devices via a system-provided chooser or
permission dialog.

Device access may be restricted when the application is in the background or in a cached
state to ensure system security and resource efficiency.

## Summary

| ### Public methods ||
|---|---|
| ` boolean` | ` https://developer.android.com/reference/android/hardware/hid/HidManager#canEnumerateDevices()() ` Checks if the calling app has the necessary permissions to enumerate connected HID devices. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/hardware/hid/HidDevice>` | ` https://developer.android.com/reference/android/hardware/hid/HidManager#getDevices()() ` Returns a list of all currently connected HID devices. |
| ` void` | ` https://developer.android.com/reference/android/hardware/hid/HidManager#registerListener(android.hardware.hid.HidDeviceListener,%20java.util.concurrent.Executor)(https://developer.android.com/reference/android/hardware/hid/HidDeviceListener listener, https://developer.android.com/reference/java/util/concurrent/Executor executor) ` Registers a listener to receive notifications about HID device lifecycle events. |
| ` void` | ` https://developer.android.com/reference/android/hardware/hid/HidManager#unregisterListener(android.hardware.hid.HidDeviceListener)(https://developer.android.com/reference/android/hardware/hid/HidDeviceListener listener) ` Unregisters a previously registered listener for HID device lifecycle events. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Public methods

### canEnumerateDevices

Added in [version 37.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public boolean canEnumerateDevices ()
```

Checks if the calling app has the necessary permissions to enumerate connected HID devices.

<br />

| Returns ||
|---|---|
| `boolean` | `true` if the calling app can enumerate HIDs, `false` otherwise. <br /> |

### getDevices

Added in [version 37.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public List<HidDevice> getDevices ()
```

Returns a list of all currently connected HID devices.

The returned list contains `https://developer.android.com/reference/android/hardware/hid/HidDevice` objects representing each connected HID node
that the system has detected and made available.

It is recommended to call `https://developer.android.com/reference/android/hardware/hid/HidManager#canEnumerateDevices()` before calling this method.


This method may take several seconds to complete, so it should
only be called from a worker thread.


Requires `https://developer.android.com/reference/android/Manifest.permission#ACCESS_HID`

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/hardware/hid/HidDevice>` | a list of connected HID devices, or an empty list if no devices are connected. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if called on the main thread. |
| `https://developer.android.com/reference/java/lang/SecurityException` | if the caller does not have the `https://developer.android.com/reference/android/Manifest.permission#ACCESS_HID` permission or if `https://developer.android.com/reference/android/hardware/hid/HidManager#canEnumerateDevices()` returns `false`. |

### registerListener

Added in [version 37.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public void registerListener (HidDeviceListener listener, 
                Executor executor)
```

Registers a listener to receive notifications about HID device lifecycle events.

When a HID device is physically connected to or disconnected from the system, the
provided `https://developer.android.com/reference/android/hardware/hid/HidDeviceListener` will be notified. If the listener is already
registered, this call does nothing.

All callback methods on the listener will be invoked using the provided `https://developer.android.com/reference/java/util/concurrent/Executor`.

Upon registration, `https://developer.android.com/reference/android/hardware/hid/HidDeviceListener#onHidDeviceAdded(android.hardware.hid.HidDevice)` will be
immediately invoked for all HID devices currently connected to the system.


Requires `https://developer.android.com/reference/android/Manifest.permission#ACCESS_HID`

<br />

| Parameters ||
|---|---|
| `listener` | `HidDeviceListener`: The listener to receive device addition and removal events. Must not be `null`. <br /> |
| `executor` | `Executor`: The executor on which the listener methods will be invoked. Must not be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |

**See also:**

- `https://developer.android.com/reference/android/hardware/hid/HidManager#unregisterListener(android.hardware.hid.HidDeviceListener)`

### unregisterListener

Added in [version 37.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public void unregisterListener (HidDeviceListener listener)
```

Unregisters a previously registered listener for HID device lifecycle events.

Once unregistered, the listener will no longer receive notifications when HID
devices are added to or removed from the system. If the provided listener was
not previously registered via `https://developer.android.com/reference/android/hardware/hid/HidManager#registerListener(android.hardware.hid.HidDeviceListener,%20java.util.concurrent.Executor)`, this call does nothing.

After this method returns, no further callbacks will be dispatched to the
executor associated with this listener.


Requires `https://developer.android.com/reference/android/Manifest.permission#ACCESS_HID`

<br />

| Parameters ||
|---|---|
| `listener` | `HidDeviceListener`: The listener to unregister. Must not be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/hardware/hid/HidManager#registerListener(android.hardware.hid.HidDeviceListener,%20java.util.concurrent.Executor)`