簡體   English   中英

如何在Android中掛載USB路徑?

[英]How to mount USB Path in android?

我正在使用android選項卡Ice Cream Sandwich版本4.0.3運行我的應用程序。 我正在連接外部USB設備和android Tab。 如何以編程方式安裝外部USB設備的路徑。 因為我需要將文件從USB設備瀏覽到我的android選項卡。

那么如何在Android中掛載USB路徑呢?

我同意user370305

您可以在“存儲設置”中查看。 安裝路徑似乎在那里(例如/mnt/usbdisk_1.0/)。 另外,您也許可以只查看/ mnt並查看其中列出的內容。 我相信這就是各種文件管理器應用程序所做的。 USB驅動器似乎有許多掛載點。 尚未掛載的文件將顯示為空,而已掛載的文件可讓您瀏覽(使用Astro這樣的文件瀏覽器應用程序)。

通過此鏈接

已經給出答案檢查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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM