【问题标题】:How to get USB Directory file path in Android 6.0 Marshmallow?如何在 Android 6.0 Marshmallow 中获取 USB 目录文件路径?
【发布时间】:2017-04-19 10:41:55
【问题描述】:

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

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

谢谢, 吉里什

【问题讨论】:

    标签: android file path


    【解决方案1】:

    通过此代码获取所有已安装的设备:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-29
      • 2016-01-24
      • 2015-04-20
      • 1970-01-01
      • 2011-09-01
      • 1970-01-01
      相关资源
      最近更新 更多