UsbManagerpublic class UsbManager extends Object This is a wrapper class for the USB Manager to support USB accessories.
You can obtain an instance of this class by calling {@link #getInstance} |
Fields Summary |
---|
private static final String | TAG | public static final String | ACTION_USB_ACCESSORY_ATTACHEDBroadcast Action: A broadcast for USB accessory attached event.
This intent is sent when a USB accessory is attached.
Call {@link #getAccessory(android.content.Intent)} to retrieve the
{@link com.google.android.usb.UsbAccessory} for the attached accessory. | public static final String | ACTION_USB_ACCESSORY_DETACHEDBroadcast Action: A broadcast for USB accessory detached event.
This intent is sent when a USB accessory is detached.
Call {@link #getAccessory(android.content.Intent)} to retrieve the
{@link com.google.android.usb.UsbAccessory} for the attached accessory that was detached. | public static final String | EXTRA_PERMISSION_GRANTEDName of extra added to the {@link android.app.PendingIntent}
passed into {#requestPermission} or {#requestPermission}
containing a boolean value indicating whether the user granted permission or not. | private final android.content.Context | mContext | private final android.hardware.usb.IUsbManager | mService |
Methods Summary |
---|
public static UsbAccessory | getAccessory(android.content.Intent intent)Returns the {@link com.google.android.usb.UsbAccessory} for
a {@link #ACTION_USB_ACCESSORY_ATTACHED} or {@link #ACTION_USB_ACCESSORY_ATTACHED}
broadcast Intent. This can also be used to retrieve the accessory from the result
of a call to {#requestPermission}.
android.hardware.usb.UsbAccessory accessory =
intent.getParcelableExtra(android.hardware.usb.UsbManager.EXTRA_ACCESSORY);
if (accessory == null) {
return null;
} else {
return new UsbAccessory(accessory);
}
| public UsbAccessory[] | getAccessoryList()Returns a list of currently attached USB accessories.
(in the current implementation there can be at most one)
try {
android.hardware.usb.UsbAccessory accessory = mService.getCurrentAccessory();
if (accessory == null) {
return null;
} else {
return new UsbAccessory[] { new UsbAccessory(accessory) };
}
} catch (RemoteException e) {
Log.e(TAG, "RemoteException in getAccessoryList" , e);
return null;
}
| public static com.android.future.usb.UsbManager | getInstance(android.content.Context context)Returns a new instance of this class.
IBinder b = ServiceManager.getService(Context.USB_SERVICE);
return new UsbManager(context, IUsbManager.Stub.asInterface(b));
| public boolean | hasPermission(UsbAccessory accessory)Returns true if the caller has permission to access the accessory.
Permission might have been granted temporarily via
{@link #requestPermission} or
by the user choosing the caller as the default application for the accessory.
try {
return mService.hasAccessoryPermission(new android.hardware.usb.UsbAccessory(
accessory.getManufacturer(),accessory.getModel(),
accessory.getDescription(), accessory.getVersion(),
accessory.getUri(), accessory.getSerial()));
} catch (RemoteException e) {
Log.e(TAG, "RemoteException in hasPermission", e);
return false;
}
| public android.os.ParcelFileDescriptor | openAccessory(UsbAccessory accessory)Opens a file descriptor for reading and writing data to the USB accessory.
try {
return mService.openAccessory(new android.hardware.usb.UsbAccessory(
accessory.getManufacturer(),accessory.getModel(),
accessory.getDescription(), accessory.getVersion(),
accessory.getUri(), accessory.getSerial()));
} catch (RemoteException e) {
Log.e(TAG, "RemoteException in openAccessory" , e);
return null;
}
| public void | requestPermission(UsbAccessory accessory, android.app.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 {@link android.app.PendingIntent} pi.
The boolean extra {@link #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.
try {
mService.requestAccessoryPermission(new android.hardware.usb.UsbAccessory(
accessory.getManufacturer(),accessory.getModel(),
accessory.getDescription(), accessory.getVersion(),
accessory.getUri(), accessory.getSerial()),
mContext.getPackageName(), pi);
} catch (RemoteException e) {
Log.e(TAG, "RemoteException in requestPermission", e);
}
|
|