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.
You can obtain an instance of this class by calling
Context.getSystemService()
.
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
For more information about communicating with USB hardware, read the USB developer guide.
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 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(UsbDevice, PendingIntent)
or requestPermission(UsbAccessory, PendingIntent)
containing a boolean value indicating whether the user granted permission or not. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns a list of currently attached USB accessories.
| |||||||||||
Returns a HashMap containing all USB devices currently attached.
| |||||||||||
Returns true if the caller has permission to access the device.
| |||||||||||
Returns true if the caller has permission to access the accessory.
| |||||||||||
Opens a file descriptor for reading and writing data to the USB accessory.
| |||||||||||
Opens the device so it can be used to send and receive
data using
UsbRequest . | |||||||||||
Requests temporary permission for the given package to access the accessory.
| |||||||||||
Requests temporary permission for the given package to access the device.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Broadcast Action: A broadcast for USB accessory attached event. This intent is sent when a USB accessory is attached.
EXTRA_ACCESSORY
containing the UsbAccessory
for the attached accessory
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
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_DEVICE
containing the UsbDevice
for the attached device
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
Name of extra for ACTION_USB_ACCESSORY_ATTACHED
and
ACTION_USB_ACCESSORY_DETACHED
broadcasts
containing the UsbAccessory object for the accessory.
Name of extra for ACTION_USB_DEVICE_ATTACHED
and
ACTION_USB_DEVICE_DETACHED
broadcasts
containing the UsbDevice object for the device.
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.
Returns a list of currently attached USB accessories. (in the current implementation there can be at most one)
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 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.
device | to check permissions for |
---|
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.
accessory | to check permissions for |
---|
Opens a file descriptor for reading and writing data to the USB accessory.
accessory | the USB accessory to open |
---|
Opens the device so it can be used to send and receive
data using UsbRequest
.
device | the device to open |
---|
UsbDeviceConnection
, or null
if open failed
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
accessory | to request permissions for |
---|---|
pi | PendingIntent for returning result |
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
device | to request permissions for |
---|---|
pi | PendingIntent for returning result |