Methods Summary |
---|
public void | addListener(com.android.camerabrowser.MtpClient$Listener listener)Registers a {@link android.mtp.MtpClient.Listener} interface to receive
notifications when MTP or PTP devices are added or removed.
synchronized (mDevices) {
if (!mListeners.contains(listener)) {
mListeners.add(listener);
}
}
|
public void | close()Closes all resources related to the MtpClient object
mContext.unregisterReceiver(mUsbReceiver);
|
public boolean | deleteObject(java.lang.String deviceName, int objectHandle)Deletes an object on the MTP or PTP device with the given USB device name.
MtpDevice device = getDevice(deviceName);
if (device == null) {
return false;
}
return device.deleteObject(objectHandle);
|
public android.mtp.MtpDevice | getDevice(java.lang.String deviceName)Retrieves an {@link android.mtp.MtpDevice} object for the USB device
with the given name.
synchronized (mDevices) {
return mDevices.get(deviceName);
}
|
public android.mtp.MtpDevice | getDevice(int id)Retrieves an {@link android.mtp.MtpDevice} object for the USB device
with the given ID.
synchronized (mDevices) {
return mDevices.get(UsbDevice.getDeviceName(id));
}
|
public java.util.List | getDeviceList()Retrieves a list of all currently connected {@link android.mtp.MtpDevice}.
synchronized (mDevices) {
// Query the USB manager since devices might have attached
// before we added our listener.
for (UsbDevice usbDevice : mUsbManager.getDeviceList().values()) {
if (mDevices.get(usbDevice.getDeviceName()) == null) {
openDeviceLocked(usbDevice);
}
}
return new ArrayList<MtpDevice>(mDevices.values());
}
|
public byte[] | getObject(java.lang.String deviceName, int objectHandle, int objectSize)Returns the data for an object as a byte array.
MtpDevice device = getDevice(deviceName);
if (device == null) {
return null;
}
return device.getObject(objectHandle, objectSize);
|
public android.mtp.MtpObjectInfo | getObjectInfo(java.lang.String deviceName, int objectHandle)Retrieves the {@link android.mtp.MtpObjectInfo} for an object on
the MTP or PTP device with the given USB device name with the given
object handle
MtpDevice device = getDevice(deviceName);
if (device == null) {
return null;
}
return device.getObjectInfo(objectHandle);
|
public java.util.List | getObjectList(java.lang.String deviceName, int storageId, int objectHandle)Retrieves a list of {@link android.mtp.MtpObjectInfo} for all objects
on the MTP or PTP device with the given USB device name and given storage ID
and/or object handle.
If the object handle is zero, then all objects in the root of the storage unit
will be returned. Otherwise, all immediate children of the object will be returned.
If the storage ID is also zero, then all objects on all storage units will be returned.
MtpDevice device = getDevice(deviceName);
if (device == null) {
return null;
}
if (objectHandle == 0) {
// all objects in root of storage
objectHandle = 0xFFFFFFFF;
}
int[] handles = device.getObjectHandles(storageId, 0, objectHandle);
if (handles == null) {
return null;
}
int length = handles.length;
ArrayList<MtpObjectInfo> objectList = new ArrayList<MtpObjectInfo>(length);
for (int i = 0; i < length; i++) {
MtpObjectInfo info = device.getObjectInfo(handles[i]);
if (info == null) {
Log.w(TAG, "getObjectInfo failed");
} else {
objectList.add(info);
}
}
return objectList;
|
public java.util.List | getStorageList(java.lang.String deviceName)Retrieves a list of all {@link android.mtp.MtpStorageInfo}
for the MTP or PTP device with the given USB device name
MtpDevice device = getDevice(deviceName);
if (device == null) {
return null;
}
int[] storageIds = device.getStorageIds();
if (storageIds == null) {
return null;
}
int length = storageIds.length;
ArrayList<MtpStorageInfo> storageList = new ArrayList<MtpStorageInfo>(length);
for (int i = 0; i < length; i++) {
MtpStorageInfo info = device.getStorageInfo(storageIds[i]);
if (info == null) {
Log.w(TAG, "getStorageInfo failed");
} else {
storageList.add(info);
}
}
return storageList;
|
public byte[] | getThumbnail(java.lang.String deviceName, int objectHandle)Returns the thumbnail data for an object as a byte array.
MtpDevice device = getDevice(deviceName);
if (device == null) {
return null;
}
return device.getThumbnail(objectHandle);
|
public boolean | importFile(java.lang.String deviceName, int objectHandle, java.lang.String destPath)Copies the data for an object to a file in external storage.
MtpDevice device = getDevice(deviceName);
if (device == null) {
return false;
}
return device.importFile(objectHandle, destPath);
|
public static boolean | isCamera(android.hardware.usb.UsbDevice device)Tests to see if a {@link android.hardware.usb.UsbDevice}
supports the PTP protocol (typically used by digital cameras)
int count = device.getInterfaceCount();
for (int i = 0; i < count; i++) {
UsbInterface intf = device.getInterface(i);
if (intf.getInterfaceClass() == UsbConstants.USB_CLASS_STILL_IMAGE &&
intf.getInterfaceSubclass() == 1 &&
intf.getInterfaceProtocol() == 1) {
return true;
}
}
return false;
|
private android.mtp.MtpDevice | openDeviceLocked(android.hardware.usb.UsbDevice usbDevice)Opens the {@link android.hardware.usb.UsbDevice} for an MTP or PTP
device and return an {@link android.mtp.MtpDevice} for it.
if (isCamera(usbDevice)) {
if (!mUsbManager.hasPermission(usbDevice)) {
mUsbManager.requestPermission(usbDevice, mPermissionIntent);
} else {
UsbDeviceConnection connection = mUsbManager.openDevice(usbDevice);
if (connection != null) {
MtpDevice mtpDevice = new MtpDevice(usbDevice);
if (mtpDevice.open(connection)) {
mDevices.put(usbDevice.getDeviceName(), mtpDevice);
return mtpDevice;
}
}
}
}
return null;
|
public void | removeListener(com.android.camerabrowser.MtpClient$Listener listener)Unregisters a {@link android.mtp.MtpClient.Listener} interface.
synchronized (mDevices) {
mListeners.remove(listener);
}
|