# Print output for @column tags ?>
Developers

- Design
- Develop
- Distribute

Developer Console

## Most visited

## Recently visited

## Results for

Summary: Constants | Methods | Inherited Methods

# UsbManager

`public class UsbManager`
`extends Object` ``

java.lang.Object
↳ | android.hardware.usb.UsbManager

This class allows you to access the state of USB and communicate with USB devices. Currently only host mode is supported in the public API.

### Developer Guides

For more information about communicating with USB hardware, read the USB developer guide.

## Summary

### Constants
`String` | `ACTION_USB_ACCESSORY_ATTACHED` Activity intent sent when user attaches a USB accessory.
`String` | `ACTION_USB_ACCESSORY_DETACHED` Broadcast Action: A broadcast for USB accessory detached event.
`String` | `ACTION_USB_DEVICE_ATTACHED` Activity intent sent when user attaches a USB device.
`String` | `ACTION_USB_DEVICE_DETACHED` Broadcast Action: A broadcast for USB device detached event.
`String` | `EXTRA_ACCESSORY` Name of extra for `ACTION_USB_ACCESSORY_ATTACHED` and `ACTION_USB_ACCESSORY_DETACHED` broadcasts containing the `UsbAccessory` object for the accessory.
`String` | `EXTRA_DEVICE` Name of extra for `ACTION_USB_DEVICE_ATTACHED` and `ACTION_USB_DEVICE_DETACHED` broadcasts containing the `UsbDevice` object for the device.
`String` | `EXTRA_PERMISSION_GRANTED` Name of extra added to the `PendingIntent` passed into `requestPermission(android.hardware.usb.UsbDevice, android.app.PendingIntent)` or `requestPermission(android.hardware.usb.UsbAccessory, android.app.PendingIntent)` containing a boolean value indicating whether the user granted permission or not.

### Public methods
`UsbAccessory[]` | `getAccessoryList()` Returns a list of currently attached USB accessories.
`HashMap<String, UsbDevice>` | `getDeviceList()` Returns a HashMap containing all USB devices currently attached.
`boolean` | `hasPermission(UsbAccessory accessory)` Returns true if the caller has permission to access the accessory.
`boolean` | `hasPermission(UsbDevice device)` Returns true if the caller has permission to access the device.
`ParcelFileDescriptor` | `openAccessory(UsbAccessory accessory)` Opens a file descriptor for reading and writing data to the USB accessory.
`UsbDeviceConnection` | `openDevice(UsbDevice device)` Opens the device so it can be used to send and receive data using `UsbRequest`.
`void` | `requestPermission(UsbDevice device, PendingIntent pi)` Requests temporary permission for the given package to access the device.
`void` | `requestPermission(UsbAccessory accessory, PendingIntent pi)` Requests temporary permission for the given package to access the accessory.

### Inherited methods
From class `java.lang.Object`
`Object` | `clone()` Creates and returns a copy of this object.
`boolean` | `equals(Object obj)` Indicates whether some other object is "equal to" this one.
`void` | `finalize()` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
`final Class<?>` | `getClass()` Returns the runtime class of this `Object`.
`int` | `hashCode()` Returns a hash code value for the object.
`final void` | `notify()` Wakes up a single thread that is waiting on this object's monitor.
`final void` | `notifyAll()` Wakes up all threads that are waiting on this object's monitor.
`String` | `toString()` Returns a string representation of the object.
`final void` | `wait(long timeout, int nanos)` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
`final void` | `wait(long timeout)` Causes the current thread to wait until either another thread invokes the `notify()` method or the `notifyAll()` method for this object, or a specified amount of time has elapsed.
`final void` | `wait()` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object.

## Constants

### ACTION_USB_ACCESSORY_ATTACHED

    public static final String ACTION_USB_ACCESSORY_ATTACHED

Activity intent sent when user attaches a USB accessory.

- `EXTRA_ACCESSORY` containing the `UsbAccessory` for the attached accessory

Constant Value: "android.hardware.usb.action.USB_ACCESSORY_ATTACHED"

### ACTION_USB_ACCESSORY_DETACHED

    public static final String ACTION_USB_ACCESSORY_DETACHED

Broadcast Action: A broadcast for USB accessory detached event. This intent is sent when a USB accessory is detached.

- `EXTRA_ACCESSORY` containing the `UsbAccessory` for the attached accessory that was detached

Constant Value: "android.hardware.usb.action.USB_ACCESSORY_DETACHED"

### ACTION_USB_DEVICE_ATTACHED

    public static final String ACTION_USB_DEVICE_ATTACHED

Activity intent sent when user attaches a USB device. This intent is sent when a USB device is attached to the USB bus when in host mode.

- `EXTRA_DEVICE` containing the `UsbDevice` for the attached device

Constant Value: "android.hardware.usb.action.USB_DEVICE_ATTACHED"

### ACTION_USB_DEVICE_DETACHED

    public static final String ACTION_USB_DEVICE_DETACHED

Broadcast Action: A broadcast for USB device detached event. This intent is sent when a USB device is detached from the USB bus when in host mode.

- `EXTRA_DEVICE` containing the `UsbDevice` for the detached device

Constant Value: "android.hardware.usb.action.USB_DEVICE_DETACHED"

### EXTRA_ACCESSORY

    public static final String EXTRA_ACCESSORY

Name of extra for `ACTION_USB_ACCESSORY_ATTACHED` and `ACTION_USB_ACCESSORY_DETACHED` broadcasts containing the `UsbAccessory` object for the accessory.

Constant Value: "accessory"

### EXTRA_DEVICE

    public static final String EXTRA_DEVICE

Name of extra for `ACTION_USB_DEVICE_ATTACHED` and `ACTION_USB_DEVICE_DETACHED` broadcasts containing the `UsbDevice` object for the device.

Constant Value: "device"

### EXTRA_PERMISSION_GRANTED

    public static final String EXTRA_PERMISSION_GRANTED

Name of extra added to the `PendingIntent` passed into `requestPermission(android.hardware.usb.UsbDevice, android.app.PendingIntent)` or `requestPermission(android.hardware.usb.UsbAccessory, android.app.PendingIntent)` containing a boolean value indicating whether the user granted permission or not.

Constant Value: "permission"

## Public methods

### getAccessoryList

    public UsbAccessory[] getAccessoryList ()

Returns a list of currently attached USB accessories. (in the current implementation there can be at most one)
Requires the `PackageManager#FEATURE_USB_ACCESSORY` feature which can be detected using `PackageManager.hasSystemFeature(String)`.

Returns
`UsbAccessory[]` | list of USB accessories, or null if none are attached.

### getDeviceList

    public HashMap<String, UsbDevice> getDeviceList ()

Returns a HashMap containing all USB devices currently attached. USB device name is the key for the returned HashMap. The result will be empty if no devices are attached, or if USB host mode is inactive or unsupported.
Requires the `PackageManager#FEATURE_USB_HOST` feature which can be detected using `PackageManager.hasSystemFeature(String)`.

Returns
`HashMap<String, UsbDevice>` | HashMap containing all connected USB devices.

### hasPermission

    public boolean hasPermission (UsbAccessory accessory)

Returns true if the caller has permission to access the accessory. Permission might have been granted temporarily via `requestPermission(android.hardware.usb.UsbAccessory, android.app.PendingIntent)` or by the user choosing the caller as the default application for the accessory.
Requires the `PackageManager#FEATURE_USB_ACCESSORY` feature which can be detected using `PackageManager.hasSystemFeature(String)`.

Parameters
`accessory` | `UsbAccessory`: to check permissions for

Returns
`boolean` | true if caller has permission

### hasPermission

    public boolean hasPermission (UsbDevice device)

Returns true if the caller has permission to access the device. Permission might have been granted temporarily via `requestPermission(android.hardware.usb.UsbDevice, android.app.PendingIntent)` or by the user choosing the caller as the default application for the device. Permission for USB devices of class `UsbConstants#USB_CLASS_VIDEO` for clients that target SDK `Build.VERSION_CODES.P` and above can be granted only if they have additionally the `Manifest.permission.CAMERA` permission.
Requires the `PackageManager#FEATURE_USB_HOST` feature which can be detected using `PackageManager.hasSystemFeature(String)`.

Parameters
`device` | `UsbDevice`: to check permissions for

Returns
`boolean` | true if caller has permission

### openAccessory

    public ParcelFileDescriptor openAccessory (UsbAccessory accessory)

Opens a file descriptor for reading and writing data to the USB accessory.

If data is read from the `InputStream` created from this file descriptor all data of a USB transfer should be read at once. If only a partial request is read the rest of the transfer is dropped.
Requires the `PackageManager#FEATURE_USB_ACCESSORY` feature which can be detected using `PackageManager.hasSystemFeature(String)`.

Parameters
`accessory` | `UsbAccessory`: the USB accessory to open

Returns
`ParcelFileDescriptor` | file descriptor, or null if the accessory could not be opened.

### openDevice

    public UsbDeviceConnection openDevice (UsbDevice device)

Opens the device so it can be used to send and receive data using `UsbRequest`.
Requires the `PackageManager#FEATURE_USB_HOST` feature which can be detected using `PackageManager.hasSystemFeature(String)`.

Parameters
`device` | `UsbDevice`: the device to open

Returns
`UsbDeviceConnection` | a `UsbDeviceConnection`, or `null` if open failed

### requestPermission

    public void requestPermission (UsbDevice device,
                    PendingIntent pi)

Requests temporary permission for the given package to access the device. This may result in a system dialog being displayed to the user if permission had not already been granted. Success or failure is returned via the `PendingIntent` pi. If successful, this grants the caller permission to access the device only until the device is disconnected. The following extras will be added to pi:

- `EXTRA_DEVICE` containing the device passed into this call
- `EXTRA_PERMISSION_GRANTED` containing boolean indicating whether permission was granted by the user

Permission for USB devices of class `UsbConstants#USB_CLASS_VIDEO` for clients that target SDK `Build.VERSION_CODES.P` and above can be granted only if they have additionally the `Manifest.permission.CAMERA` permission.
Requires the `PackageManager#FEATURE_USB_HOST` feature which can be detected using `PackageManager.hasSystemFeature(String)`.

Parameters
`device` | `UsbDevice`: to request permissions for
`pi` | `PendingIntent`: PendingIntent for returning result

### requestPermission

    public void requestPermission (UsbAccessory accessory,
                    PendingIntent pi)

Requests temporary permission for the given package to access the accessory. This may result in a system dialog being displayed to the user if permission had not already been granted. Success or failure is returned via the `PendingIntent` pi. If successful, this grants the caller permission to access the accessory only until the device is disconnected. The following extras will be added to pi:

- `EXTRA_ACCESSORY` containing the accessory passed into this call
- `EXTRA_PERMISSION_GRANTED` containing boolean indicating whether permission was granted by the user

Requires the `PackageManager#FEATURE_USB_ACCESSORY` feature which can be detected using `PackageManager.hasSystemFeature(String)`.

Parameters
`accessory` | `UsbAccessory`: to request permissions for
`pi` | `PendingIntent`: PendingIntent for returning result

Full name *
Email address *
Company / developer name
One of your Play Store app URLs *
Which best describes your business:*
Apps
Games
Apps & Games
*
*