安卓检测usb挂载点路径 [英] Android detect usb mount point path

查看:49
本文介绍了安卓检测usb挂载点路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款可以连接到 USB SD 读卡器的应用.问题是所有手机的 USB 路径都不相同.我知道在三星手机中,USB 路径是/storage/UsbDriveA/"

I am working on a app that can connect to a USB SD card reader. The problem is the USB path is not the same for all the phones. I know that in Samsung phones the USB path is "/storage/UsbDriveA/"

我的问题是如何找到所有手机设备的 USB 安装路径?

My question is how can I find the USB mount path for all phone devices?

谢谢

推荐答案

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

这篇关于安卓检测usb挂载点路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆