HidManager
public
final
class
HidManager
extends Object
| java.lang.Object | |
| ↳ | android.hardware.hid.HidManager |
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 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
|
canEnumerateDevices()
Checks if the calling app has the necessary permissions to enumerate connected HID devices. |
List<HidDevice>
|
getDevices()
Returns a list of all currently connected HID devices. |
void
|
registerListener(HidDeviceListener listener, Executor executor)
Registers a listener to receive notifications about HID device lifecycle events. |
void
|
unregisterListener(HidDeviceListener listener)
Unregisters a previously registered listener for HID device lifecycle events. |
Inherited methods | |
|---|---|
Public methods
canEnumerateDevices
public boolean canEnumerateDevices ()
Checks if the calling app has the necessary permissions to enumerate connected HID devices.
| Returns | |
|---|---|
boolean |
true if the calling app can enumerate HIDs, false otherwise. |
getDevices
public List<HidDevice> getDevices ()
Returns a list of all currently connected HID devices.
The returned list contains HidDevice objects representing each connected HID node
that the system has detected and made available.
It is recommended to call canEnumerateDevices() before calling this method.
This method may take several seconds to complete, so it should
only be called from a worker thread.
Requires Manifest.permission.ACCESS_HID
| Returns | |
|---|---|
List<HidDevice> |
a list of connected HID devices, or an empty list if no devices are connected.
This value cannot be null. |
| Throws | |
|---|---|
IllegalStateException |
if called on the main thread. |
SecurityException |
if the caller does not have the
Manifest.permission.ACCESS_HID permission or if
canEnumerateDevices() returns false. |
registerListener
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 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 Executor.
Upon registration, HidDeviceListener.onHidDeviceAdded(HidDevice) will be
immediately invoked for all HID devices currently connected to the system.
Requires Manifest.permission.ACCESS_HID
| Parameters | |
|---|---|
listener |
HidDeviceListener: The listener to receive device addition and removal events. Must not be null. |
executor |
Executor: The executor on which the listener methods will be invoked. Must not be null.
Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is
used. To dispatch events through the main thread of your
application, you can use
Context.getMainExecutor().
Otherwise, provide an Executor that dispatches to an appropriate thread. |
See also:
unregisterListener
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 registerListener(HidDeviceListener, Executor), this call does nothing.
After this method returns, no further callbacks will be dispatched to the
executor associated with this listener.
Requires Manifest.permission.ACCESS_HID
| Parameters | |
|---|---|
listener |
HidDeviceListener: The listener to unregister. Must not be null. |