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.
Instances of this class must be obtained using Context.getSystemService(Class) with the argument UsbManager.class or Context.getSystemService(String) with the argument Context.USB_SERVICE.
Summary
Constants | |
|---|---|
String |
ACTION_USB_ACCESSORY_ATTACHED
Broadcast Action: A broadcast for USB accessory attached event. |
String |
ACTION_USB_ACCESSORY_DETACHED
Broadcast Action: A broadcast for USB accessory detached event. |
String |
ACTION_USB_DEVICE_ATTACHED
Broadcast Action: A broadcast for USB device attached event. |
String |
ACTION_USB_DEVICE_DETACHED
Broadcast Action: A broadcast for USB device detached event. |
String |
EXTRA_ACCESSORY
Name of extra for |
String |
EXTRA_DEVICE
Name of extra for |
String |
EXTRA_PERMISSION_GRANTED
Name of extra added to the |
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 |
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 | |
|---|---|
java.lang.Object
| |
Constants
ACTION_USB_ACCESSORY_ATTACHED
String ACTION_USB_ACCESSORY_ATTACHED
Broadcast Action: A broadcast for USB accessory attached event. This intent is sent when a USB accessory is attached.
-
EXTRA_ACCESSORYcontaining theUsbAccessoryfor the attached accessory
Constant Value: "android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
ACTION_USB_ACCESSORY_DETACHED
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_ACCESSORYcontaining theUsbAccessoryfor the attached accessory that was detached
Constant Value: "android.hardware.usb.action.USB_ACCESSORY_DETACHED"
ACTION_USB_DEVICE_ATTACHED
String ACTION_USB_DEVICE_ATTACHED
Broadcast Action: A broadcast for USB device attached event. This intent is sent when a USB device is attached to the USB bus when in host mode.
-
EXTRA_DEVICEcontaining theUsbDevicefor the attached device
Constant Value: "android.hardware.usb.action.USB_DEVICE_ATTACHED"
ACTION_USB_DEVICE_DETACHED
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_DEVICEcontaining theUsbDevicefor the detached device
Constant Value: "android.hardware.usb.action.USB_DEVICE_DETACHED"
EXTRA_ACCESSORY
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
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
String EXTRA_PERMISSION_GRANTED
Name of extra added to the PendingIntent
passed into requestPermission(UsbDevice, PendingIntent)
or requestPermission(UsbAccessory, PendingIntent)
containing a boolean value indicating whether the user granted permission or not.
Constant Value: "permission"
Public methods
getAccessoryList
UsbAccessory[] getAccessoryList ()
Returns a list of currently attached USB accessories. (in the current implementation there can be at most one)
| Returns | |
|---|---|
UsbAccessory[] |
list of USB accessories, or null if none are attached. |
getDeviceList
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.
| Returns | |
|---|---|
HashMap<String, UsbDevice> |
HashMap containing all connected USB devices. |
hasPermission
boolean hasPermission (UsbAccessory accessory)
Returns true if the caller has permission to access the accessory.
Permission might have been granted temporarily via
requestPermission(UsbAccessory, PendingIntent) or
by the user choosing the caller as the default application for the accessory.
| Parameters | |
|---|---|
accessory |
UsbAccessory: to check permissions for |
| Returns | |
|---|---|
boolean |
true if caller has permission |
hasPermission
boolean hasPermission (UsbDevice device)
Returns true if the caller has permission to access the device.
Permission might have been granted temporarily via
requestPermission(UsbDevice, PendingIntent) or
by the user choosing the caller as the default application for the device.
| Parameters | |
|---|---|
device |
UsbDevice: to check permissions for |
| Returns | |
|---|---|
boolean |
true if caller has permission |
openAccessory
ParcelFileDescriptor openAccessory (UsbAccessory accessory)
Opens a file descriptor for reading and writing data to the USB accessory.
| Parameters | |
|---|---|
accessory |
UsbAccessory: the USB accessory to open |
| Returns | |
|---|---|
ParcelFileDescriptor |
file descriptor, or null if the accessor could not be opened. |
openDevice
UsbDeviceConnection openDevice (UsbDevice device)
Opens the device so it can be used to send and receive
data using UsbRequest.
| Parameters | |
|---|---|
device |
UsbDevice: the device to open |
| Returns | |
|---|---|
UsbDeviceConnection |
a UsbDeviceConnection, or null if open failed
|
requestPermission
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_DEVICEcontaining the device passed into this call -
EXTRA_PERMISSION_GRANTEDcontaining boolean indicating whether permission was granted by the user
| Parameters | |
|---|---|
device |
UsbDevice: to request permissions for |
pi |
PendingIntent: PendingIntent for returning result
|
requestPermission
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_ACCESSORYcontaining the accessory passed into this call -
EXTRA_PERMISSION_GRANTEDcontaining boolean indicating whether permission was granted by the user
| Parameters | |
|---|---|
accessory |
UsbAccessory: to request permissions for |
pi |
PendingIntent: PendingIntent for returning result
|


Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
