如何在 usb otg 中获取 free/total space?

How to get free/total space in usb otg?

我可以检测到我的 phone 中是否连接和分离了 usb otg,但现在我的问题是我不知道如何检索 usb otg 中的所有 information/file?

只需像 /storage/usbotg 一样获取 URI,然后执行:

File usbotgfile = new File("/storage/usbotg");
usbotgfile.getTotalSpace();
usbotgfile.getFreeSpace();

最好不要硬编码 URI 路径,而是使用:

Environment.getExternalDirectory();--> /storage/sdcard0

然后将sdcard0改为usbotg