How to get USB Directory file path in Android 6.0

2019-09-05 02:56发布

How to get file path of USB OTG in 6.0?

I am not able to get file path of Android 6.0 in USB OTG so let me know what is solution?

Thanks, Girish

1条回答
欢心
2楼-- · 2019-09-05 03:05

get all mounted devices by this code:

public String getStoragepath() {
try {
    Runtime runtime = Runtime.getRuntime();
    Process proc = runtime.exec("mount");
    InputStream is = proc.getInputStream();
    InputStreamReader isr = new InputStreamReader(is);
    String line;
    String[] patharray = new String[10];
    int i = 0;
    int available = 0;

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

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

                patharray[i] = mount;
                i++;

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

                    available = 1;
                    finalpath = mount;
                    break;
                } else {

                }
            }
        }
    }
    if (available == 1) {

    } else if (available == 0) {
        finalpath = patharray[0];
    }

} catch (Exception e) {

}
return finalpath;}
查看更多
登录 后发表回答