我正在嘗試將USB海量存儲設備安裝到我的Raspberry Pi運行Android的東西。我遇到了this答案,它顯示瞭如何使用命令行ADB shell進行掛載。 但問題是我必須在每次啓動設備時運行這些命令。我想在我的啓動活動的onCreate()
中安裝USB驅動器。下面是代碼:啓動活動時將USB U盤安裝到android的東西
//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上的物聯網應用在使用USB設備?
在Android下,它會自動掛載。所以我想知道爲什麼這不會發生在Android的東西。 – greenapps