如何在Android Things上安装USB驱动器? [英] How to mount a USB drive on Android Things?
问题描述
我正在尝试从 Raspberry Pi 上的 Android Things 应用程序的USB驱动器中读取文件.我可以像这样扫描已挂载设备的列表:
I'm attempting to read files off of a USB drive for an Android Things app on a Raspberry Pi. I'm able to scan the list of mounted devices like so:
public static List<File> ScanForFiles(Context context){
ArrayList<File> files = new ArrayList<>();
try{
BufferedReader reader = new BufferedReader(new FileReader("/proc/self/mountinfo"));
String line;
while ((line = reader.readLine()) != null) {
String[] columns = line.split(" ");
Log.i(TAG, "Mounted: " + columns[4]);
//files.addAll(getListFiles(new File(columns[4])));
}
} catch (Exception ex){
ex.printStackTrace();
}
printFileInformation("/proc/partitions");
return files;
}
private static void printFileInformation(String fileName){
Log.i("TitanTV", "Reading contents of " + fileName);
try{
BufferedReader reader = new BufferedReader(new FileReader(fileName));
String line;
while ((line = reader.readLine()) != null){
Log.i("TitanTV", line);
}
} catch (Exception ex){
ex.printStackTrace();
}
}
显示以下输出:
I: Mounted: /
I: Mounted: /dev
I: Mounted: /dev
I: Mounted: /dev/pts
I: Mounted: /dev/memcg
I: Mounted: /dev/cpuctl
I: Mounted: /proc
I: Mounted: /sys
I: Mounted: /sys/fs/selinux
I: Mounted: /sys/fs/pstore
I: Mounted: /acct
I: Mounted: /mnt
I: Mounted: /mnt/runtime/default/emulated
I: Mounted: /mnt/runtime/read/emulated
I: Mounted: /mnt/runtime/write/emulated
I: Mounted: /config
I: Mounted: /data
I: Mounted: /oem
I: Mounted: /gapps
I: Mounted: /storage
I: Mounted: /storage/emulated
I: Mounted: /storage/self
I: Reading contents of /proc/partitions
I: major minor #blocks name
I: 1 0 8192 ram0
I: 1 1 8192 ram1
I: 1 2 8192 ram2
I: 1 3 8192 ram3
I: 1 4 8192 ram4
I: 1 5 8192 ram5
I: 1 6 8192 ram6
I: 1 7 8192 ram7
I: 1 8 8192 ram8
I: 1 9 8192 ram9
I: 1 10 8192 ram10
I: 1 11 8192 ram11
I: 1 12 8192 ram12
I: 1 13 8192 ram13
I: 1 14 8192 ram14
I: 1 15 8192 ram15
I: 179 0 7761920 mmcblk0
I: 179 1 65536 mmcblk0p1
I: 179 2 1024 mmcblk0p2
I: 179 3 1024 mmcblk0p3
I: 179 4 32768 mmcblk0p4
I: 179 5 32768 mmcblk0p5
I: 179 6 524288 mmcblk0p6
I: 179 7 524288 mmcblk0p7
I: 179 8 64 mmcblk0p8
I: 179 9 64 mmcblk0p9
I: 179 10 1024 mmcblk0p10
I: 179 11 32768 mmcblk0p11
I: 179 12 32768 mmcblk0p12
I: 179 13 262144 mmcblk0p13
I: 179 14 262144 mmcblk0p14
I: 179 15 2683736 mmcblk0p15
I: 8 0 7847935 sda
I: 8 1 7845888 sda1
但是,我的拇指驱动器不在列表中.所以我想我需要以某种方式安装它.如何安装拇指驱动器并访问其中的文件?
However, my thumb drive isn't apart of the list. So I'm guessing I need to mount it in some way. How can I mount the thumb drive and access the files on it?
推荐答案
仅限ADB解决方案
似乎到目前为止,尚未自动安装USB驱动器.为了使您的代码正常工作,我必须手动安装它.
Seem like as of now USB drives aren't mounted automatically. In order to make your code work I had to mount it manually.
您可以在/proc
分区中(从/proc/partitions
中看到)将USB驱动器检测为sda
.
As you can see (from /proc/partitions
) in the /proc
partition the USB drive is detected as sda
.
ADB安装
-
创建要挂载的目录
Make a directory to mount to
mkdir /mnt/usb
安装设备
Mount the device
mount -t vfat -o rw /dev/block/sda1 /mnt/usb
现在,您应该能够通过ADB以及从应用程序内部列出(和管理)USB驱动器上的文件(/mnt/usb
也将被记录).
Now you should be able to list (and manage) the files on the USB drive both via ADB and from within the app (/mnt/usb
will also be logged).
这篇关于如何在Android Things上安装USB驱动器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!