android - 开始 Activity 时将 USB 拇指驱动器挂载到 android things

标签 android raspberry-pi3 usb-drive android-things

我正在尝试将 USB 大容量存储设备安装到运行 android things 的 Raspberry Pi。我遇到了this显示如何使用命令行 ADB shell 挂载它的答案。 但问题是每次我的设备启动时我都必须运行这些命令。我想在启动 Activity 的 onCreate() 中安装 USB 驱动器。这是代码:

//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 设备?

最佳答案

您只能在已获得 root 权限的 Android 中运行这些命令。出于安全原因,Android Things(作为 Android)不允许执行 shell 命令。

关于android - 开始 Activity 时将 USB 拇指驱动器挂载到 android things,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43865719/

相关文章:

android - 像 Sony Xperia Contacts 一样右边有字母的 ListView,有可能吗?

android - 项目刷新失败,无法打开 zip 文件

java - 在闪存驱动器上安装 Java

python - 如何使用 Python 在 Windows 中检测闪存驱动器插件?

javascript - 将对象从一个屏幕传递到另一个屏幕 | react native

android - 如何在屏幕方向上停止 Activity 娱乐?

python - 在Python中读取2字节的I2C事务

linux - 自动程序打开和工作区切换

linux - 从另一个 bash 脚本中有选择地打开和关闭 bash 脚本

linux - 使用 git 通过 U 盘在 Windows 和 Linux 之间传输数据