开始活动时将USB拇指驱动器安装到android事物上 [英] Mount USB thumb drive to android things when starting the activity
问题描述
我正在尝试将USB大容量存储设备安装到运行android系统的Raspberry Pi上.我遇到了此答案,该答案说明了如何使用命令行ADB shell进行安装.但是问题是我每次设备启动时都必须运行那些命令.我想将USB驱动器安装在启动活动的 onCreate()
中.这是代码:
I am trying to mount the USB mass storage device to my Raspberry Pi running the android things. I came across this answer which shows how to mount it using command line ADB shell.
But the problem is I have to run those command every time my device boots. I want to mount the USB drive in onCreate()
of my launch activity. Here is the code:
//Here is the mount drive function which I called in onCreate of my activity.
private void mountDrive() throws IOException, InterruptedException {
Process mProcess = Runtime.getRuntime().exec("/system/xbin/su");
BufferedReader reader = new BufferedReader(new InputStreamReader(mProcess.getInputStream()));
DataOutputStream dos = new DataOutputStream(mProcess.getOutputStream());
dos.writeBytes("mkdir /mnt/usb\n");
dos.flush();
dos.writeBytes("mount -t vfat -o rw /dev/block/sda1 /mnt/usb\n");
dos.flush();
dos.writeBytes("exit\n");
//Read the response
String line, result = "";
while ((line = reader.readLine()) != null) {
result += line;
Log.d("CMD","RESULT:"+result);
}
reader.close();
dos.flush();
dos.close();
mProcess.waitFor();
}
但是我收到此错误:
I/sh: type=1400 audit(0.0:31): avc: denied { read } for name="/" dev="mmcblk0p6" ino=2 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:rootfs:s0 tclass=dir permissive=1
I/sh: type=1400 audit(0.0:32): avc: denied { open } for path="/" dev="mmcblk0p6" ino=2 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:rootfs:s0 tclass=dir permissive=1
W/System.err: java.io.IOException: Cannot run program "su": error=13, Permission denied
W/System.err: at java.lang.ProcessBuilder.start(ProcessBuilder.java:983)
W/System.err: at java.lang.Runtime.exec(Runtime.java:691)
W/System.err: at java.lang.Runtime.exec(Runtime.java:524)
W/System.err: at java.lang.Runtime.exec(Runtime.java:421)
如何在我的Android Things中使用我的应用程序挂载USB设备?
How can I mount the USB device using from my application on Android Things?
推荐答案
另一种方法是修改 init.rc
文件.在 init.rc
文件中搜索 on属性:sys.boot_completed = 1
:
An alternative is to modify the init.rc
file. Search the init.rc
file for on property: sys.boot_completed = 1
:
on property: sys.boot_completed = 1
bootchart stop
# WLD 201805031702
mkdir / mnt / usb
chmod 777 / mnt / usb
exec / system / bin / mount -t vfat / dev / block / sda1 / mnt / usb
#operate only if the pendrive is placed before powering on, if you remove and put it will not work
这篇关于开始活动时将USB拇指驱动器安装到android事物上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!