我已将设备的存储空间添加为USB笔式驱动器,但我不知道如何从USB中获取文件。

我试过了,但是没有用:

HashMap<String, UsbDevice> usbDevices = usbManager.getDeviceList();
HashMap<String, UsbDevice> usbDevices1 = new HashMap<>();
usbDevices1.clear();

if (!usbDevices.isEmpty()) {
    boolean keep = true;
    for (Map.Entry<String, UsbDevice> entry : usbDevices.entrySet()) {
        device = entry.getValue();
        int deviceVID = device.getVendorId();
        int devicePID = device.getProductId();
        if (deviceVID == 1659 && devicePID == 8963) {
            if (deviceVID != 0x1d6b && (devicePID != 0x0001 || devicePID != 0x0002 || devicePID != 0x0003)) {
                // There is a device connected to our Android device. Try to open it as a Serial Port.
                requestUserPermission();
                keep = false;
            } else {
                    connection = null;
                    device = null;
                   }

                   if (!keep)
                       break;
        }
    }
}

最佳答案

USB闪存驱动器将手机上的外部存储设备用于存储,您可以使用以下命令从外部存储读取文件:

File path = context.getExternalFilesDir(null);


或使用其他库:

https://github.com/magnusja/libaums

07-27 21:56