4

我正在使用 android tabIce Cream Sandwich版本 4.0.3 来运行我的应用程序。我正在连接外部 USB 设备和 android Tab。如何以编程方式挂载外部 USB 设备的路径。因为我需要从 USB 设备浏览文件到我的 android 选项卡。

那么如何在android中挂载USB路径?

4

2 回答 2

1

我同意user370305

您可以查看存储设置。挂载路径似乎在那里(例如,/mnt/usbdisk_1.0/)。此外,您也许可以只查看 /mnt 并查看列出的内容;我相信这就是各种文件管理器应用程序所做的。USB 驱动器似乎有许多挂载点;尚未安装的显示为空,而已安装的可让您浏览它们(使用诸如 Astro 之类的文件浏览器应用程序)。

通过这个链接

于 2012-06-25T08:58:46.667 回答
1

已经给出答案检查Android检测usb挂载点路径

  private String getAllStoragePath() {
    String finalPath = "";
    try {
        Runtime runtime = Runtime.getRuntime();
        Process process = runtime.exec("mount");
        InputStream inputStream = process.getInputStream();
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        String line;
        String[] pathArray = new String[4];
        int i = 0;

        BufferedReader br = new BufferedReader(inputStreamReader);
        while ((line = br.readLine()) != null) {
            String mount = "";
            if (line.contains("secure"))
                continue;
            if (line.contains("asec"))
                continue;

            if (line.contains("fat")) {// TF card
                String columns[] = line.split(" ");
                if (columns.length > 1) {
                    mount = mount.concat(columns[1] + "/someFiles");

                    pathArray[i++] = mount;

                    // check directory inputStream exist or not
                    File dir = new File(mount);
                    if (dir.exists() && dir.isDirectory()) {
                        // do something here
                        finalPath = mount;
                        break;
                    }
                }
            }
        }

        for(String path:pathArray){
            if(path!=null){
                finalPath =finalPath + path +"\n";
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return finalPath;
}
于 2016-05-11T12:34:16.600 回答