public class UsbManager extends Object
You can obtain an instance of this class by calling getInstance(android.content.Context)
Modifier and Type | Field and Description |
---|---|
static String |
ACTION_USB_ACCESSORY_ATTACHED
Broadcast Action: A broadcast for USB accessory attached event.
|
static String |
ACTION_USB_ACCESSORY_DETACHED
Broadcast Action: A broadcast for USB accessory detached event.
|
static String |
EXTRA_PERMISSION_GRANTED
Name of extra added to the
PendingIntent
passed into {#requestPermission} or {#requestPermission}
containing a boolean value indicating whether the user granted permission or not. |
Modifier and Type | Method and Description |
---|---|
static UsbAccessory |
getAccessory(Intent intent)
Returns the
com.google.android.usb.UsbAccessory for
a ACTION_USB_ACCESSORY_ATTACHED or ACTION_USB_ACCESSORY_ATTACHED
broadcast Intent. |
UsbAccessory[] |
getAccessoryList()
Returns a list of currently attached USB accessories.
|
static UsbManager |
getInstance(Context context)
Returns a new instance of this class.
|
boolean |
hasPermission(UsbAccessory accessory)
Returns true if the caller has permission to access the accessory.
|
ParcelFileDescriptor |
openAccessory(UsbAccessory accessory)
Opens a file descriptor for reading and writing data to the USB accessory.
|
void |
requestPermission(UsbAccessory accessory,
PendingIntent pi)
Requests temporary permission for the given package to access the accessory.
|
public static final String ACTION_USB_ACCESSORY_ATTACHED
getAccessory(android.content.Intent)
to retrieve the
com.google.android.usb.UsbAccessory
for the attached accessory.public static final String ACTION_USB_ACCESSORY_DETACHED
getAccessory(android.content.Intent)
to retrieve the
com.google.android.usb.UsbAccessory
for the attached accessory that was detached.public static final String EXTRA_PERMISSION_GRANTED
PendingIntent
passed into {#requestPermission} or {#requestPermission}
containing a boolean value indicating whether the user granted permission or not.public static UsbManager getInstance(Context context)
context
- the caller's Context
public static UsbAccessory getAccessory(Intent intent)
com.google.android.usb.UsbAccessory
for
a ACTION_USB_ACCESSORY_ATTACHED
or ACTION_USB_ACCESSORY_ATTACHED
broadcast Intent. This can also be used to retrieve the accessory from the result
of a call to {#requestPermission}.public UsbAccessory[] getAccessoryList()
public ParcelFileDescriptor openAccessory(UsbAccessory accessory)
accessory
- the USB accessory to openpublic boolean hasPermission(UsbAccessory accessory)
requestPermission(com.android.future.usb.UsbAccessory, android.app.PendingIntent)
or
by the user choosing the caller as the default application for the accessory.accessory
- to check permissions forpublic void requestPermission(UsbAccessory accessory, PendingIntent pi)
PendingIntent
pi.
The boolean extra EXTRA_PERMISSION_GRANTED
will be attached to the
PendingIntent to indicate success or failure.
If successful, this grants the caller permission to access the device only
until the device is disconnected.accessory
- to request permissions forpi
- PendingIntent for returning result