How to mount USB Path in android?

12,844

Solution 1

I am agree with user370305.

You can look in the Storage Settings. the mount paths seem to be there (for instance, /mnt/usbdisk_1.0/). Also, you might be able to just look in /mnt and see what is listed; I believe that that is what the various file manager apps do. There seem to be a number of mount points for USB drives; the ones that aren't yet mounted show up as empty, while the mounted ones let you browse into them (using a file explorer app like Astro).

Go through this link.

Solution 2

already given answer check Android detect usb mount point path

  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;
}
Share:
12,844
Jahir
Author by

Jahir

I am a Student.

Updated on July 13, 2022

Comments

  • Jahir
    Jahir almost 2 years

    I am using android tab Ice Cream Sandwich Version 4.0.3 to run my application. I am connect with external USB device and android Tab. How to i mount path of external USB device programmatically. Because i need to Browse files from USB device to my android tab.

    So How to mount USB Path in android?

  • Chris Stratton
    Chris Stratton over 9 years
    This will only work on devices where the vendor has extended Android with a non-standard ability to mount USB storage volumes. Stock Android does not support USB drives at operating system level. If a stock device has host mode, it is possible to talk to the drive at a low level using mass storage and file system code implemented in an application itself, but you are on your own with no help from the operating system's file system capabilities.
  • Diljeet
    Diljeet about 7 years
    Thanks for the code, i use it as fallback, i first check if a file "proc/mounts" is existing and i read it, if not then i read it via this script. We should not relly on "fat" or "vfat" new devices sometimes has "fuse" as partition type, its big script detecting partition, but they starts with "/dev/" and may be vfat or fuse, and you may have duplicate paths to same partition, o beware of that.