Search in sources :

Example 31 with MtpDevice

use of android.mtp.MtpDevice in project android_packages_apps_Gallery2 by LineageOS.

the class MtpClient method getStorageList.

/**
 * Retrieves a list of all {@link android.mtp.MtpStorageInfo}
 * for the MTP or PTP device with the given USB device name
 *
 * @param deviceName the name of the USB device
 * @return the list of MtpStorageInfo
 */
public List<MtpStorageInfo> getStorageList(String deviceName) {
    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;
}
Also used : MtpDevice(android.mtp.MtpDevice) ArrayList(java.util.ArrayList) MtpStorageInfo(android.mtp.MtpStorageInfo)

Example 32 with MtpDevice

use of android.mtp.MtpDevice in project android_packages_apps_Gallery2 by LineageOS.

the class MtpClient method getObjectList.

/**
 * 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.
 *
 * @param deviceName the name of the USB device
 * @param storageId the ID of the storage unit to query, or zero for all
 * @param objectHandle the handle of the parent object to query, or zero for the storage root
 * @return the list of MtpObjectInfo
 */
public List<MtpObjectInfo> getObjectList(String deviceName, int storageId, int objectHandle) {
    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;
}
Also used : MtpDevice(android.mtp.MtpDevice) ArrayList(java.util.ArrayList) MtpObjectInfo(android.mtp.MtpObjectInfo)

Example 33 with MtpDevice

use of android.mtp.MtpDevice in project android_packages_apps_Gallery2 by LineageOS.

the class IngestService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    mScannerClient = new ScannerClient(this);
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mNotificationBuilder = new NotificationCompat.Builder(this);
    // TODO(georgescu): Use a better drawable for the notificaton?
    mNotificationBuilder.setSmallIcon(android.R.drawable.stat_notify_sync).setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, IngestActivity.class), 0));
    mIndex = MtpDeviceIndex.getInstance();
    mIndex.setProgressListener(this);
    mClient = new MtpClient(getApplicationContext());
    List<MtpDevice> devices = mClient.getDeviceList();
    if (!devices.isEmpty()) {
        setDevice(devices.get(0));
    }
    mClient.addListener(this);
}
Also used : MtpDevice(android.mtp.MtpDevice) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) MtpClient(com.android.gallery3d.ingest.data.MtpClient)

Example 34 with MtpDevice

use of android.mtp.MtpDevice in project xDrip by NightscoutFoundation.

the class MtpTools method openMTP.

static synchronized MtpDevice openMTP(final UsbDevice device) {
    if (device == null) {
        return null;
    }
    final UsbManager usbManager = (UsbManager) xdrip.getAppContext().getSystemService(Context.USB_SERVICE);
    if (usbManager == null) {
        Log.d(TAG, "usbmanager is null in openMTP");
        return null;
    }
    final MtpDevice mtpDevice = new MtpDevice(device);
    final UsbDeviceConnection usbDeviceConnection = usbManager.openDevice(device);
    try {
        if (!mtpDevice.open(usbDeviceConnection)) {
            return null;
        }
    } catch (Exception e) {
        JoH.static_toast_long("Exception opening USB: " + e);
        return null;
    }
    return mtpDevice;
}
Also used : UsbDeviceConnection(android.hardware.usb.UsbDeviceConnection) MtpDevice(android.mtp.MtpDevice) UsbManager(android.hardware.usb.UsbManager) IOException(java.io.IOException)

Aggregations

MtpDevice (android.mtp.MtpDevice)34 ArrayList (java.util.ArrayList)19 MtpStorageInfo (android.mtp.MtpStorageInfo)12 IOException (java.io.IOException)12 UsbDeviceConnection (android.hardware.usb.UsbDeviceConnection)9 MtpObjectInfo (android.mtp.MtpObjectInfo)7 UsbDevice (android.hardware.usb.UsbDevice)5 MtpDeviceInfo (android.mtp.MtpDeviceInfo)5 UsbManager (android.hardware.usb.UsbManager)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 MtpClient (com.android.gallery3d.ingest.data.MtpClient)1