Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在安卓6.0棉花糖中获取USB目录文件路径?_Android_File_Path - Fatal编程技术网

Android 如何在安卓6.0棉花糖中获取USB目录文件路径?

Android 如何在安卓6.0棉花糖中获取USB目录文件路径?,android,file,path,Android,File,Path,如何在6.0中获取USB OTG的文件路径 我无法在USB OTG中获取Android 6.0的文件路径,请告诉我解决方案是什么 谢谢, Girish使用此代码获取所有已安装的设备: public String getStoragepath() { try { Runtime runtime = Runtime.getRuntime(); Process proc = runtime.exec("mount"); InputStream is = proc.getInpu

如何在6.0中获取USB OTG的文件路径

我无法在USB OTG中获取Android 6.0的文件路径,请告诉我解决方案是什么

谢谢,
Girish

使用此代码获取所有已安装的设备:

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