作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在我的设备上添加了一个存储空间作为 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);
或者使用额外的库:
关于java - 如何从 USB pendrive 获取文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52640317/
我是一名优秀的程序员,十分优秀!