Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access USB Path in android?

Tags:

android

I am connected android device and PC via USB cable. My Internal SD Card location Path as /mnt/sdcard. But my External USB device path as /mnt/userdata1. I am try to use this code to find only the Internal SD Card Path Environment.getExternalStorageDirectory(). I am using this code to access only in the internal SD Card path. How to access the external USB Path.

For example Screenshot is here... Example

In this example contains Internal Memory, External SD card and USB Storage. How to find this path ( Internal Memory, External SD card and USB Storage) programmatically. In this code Environment.getExternalStorageDirectory() is viewed files from all Internal Memory Files only. So how to access others path ( External SD card and USB Storage )

Please guide me with code. Thanks..

like image 602
Dinesh Lingam Avatar asked Jul 02 '12 10:07

Dinesh Lingam


1 Answers

If I understand correctly, what you are calling "external" USB path is actually the mount point for your SD card on your computer. Most likely, your SD card has label userdata1. Therefore when it's mounted on the computer, it gets /mnt/userdata1 mount point. However this is not strictly necessary and it can be any mount point at all. In fact, if you connect it to another computer, it can easily be another mount point.

Because this path is determined by the computer operating system, you'll need to find this path on your computer (note that this can be different every time you connect your phone to your PC, so you'll need to do it every time).

From your question and path structure (/mnt/userdata1) I'm guessing you're using linux or some other unix version. Therefore you could run mount on your PC to see the list of the mounted devices. For example, here's the output on my mac:

$ mount
/dev/disk0s2 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)
/dev/disk1s1 on /Volumes/ALEKS540 (msdos, local, nodev, nosuid, noowners)

Note the last line in the output - this is my connected android phone with the SD card mounted to the computer. On macs, the mount points are created under /Volumes instead of /mnt. Other than than, ALEKS540 is the label of my SD card, hence it's mounted this way.

Internally on the phone, it's still mounted as /mnt/sdcard.

From the point of view of Android, there may be three storage types:

  1. Internal memory it's always mounted under / on the device and contains everything except the SD card and USB storage below.
  2. SD card - this is referred to as "external storage" and is usually mounted as /mnt/sd, but not always. Environment.getExternalStorageDirectory() will return the path of SD card mount point.
  3. USB storage - this is only supported on very few devices (those that support USB host mode for external storage). This will be mounted somewhere under /mnt, but the exact location will vary. You will need to use Android NDK to interrogate and iterate mounted devices to find the one you're after.
like image 149
Aleks G Avatar answered Oct 21 '22 01:10

Aleks G