How to get USB Directory file path in Android 6.0 Marshmallow?

陌路散爱 提交于 2019-12-25 04:24:35

问题


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:


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;}


来源:https://stackoverflow.com/questions/40967472/how-to-get-usb-directory-file-path-in-android-6-0-marshmallow

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!