How to access USB circuit in android?

I connected the Android device and the PC via the USB cable. My internal SD card location card is like /mnt/sdcard . But my external USB device path is like /mnt/userdata1 . I am trying to use this code to find only the internal path of the Environment.getExternalStorageDirectory() SD card. I use this code to access only the internal path of the SD card. How to access an external USB path.

For example, a screenshot here ... Example

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() only files from all Internal Memory files are viewed. So, how to access other roads ( External SD card and USB Storage )

Please guide me with the code. Thanks..

+4
source share
1 answer

If I understand correctly, what you call the "external" USB path is actually the mount point of your SD card on your computer. Most likely, your SD card is labeled userdata1 . Therefore, when it is installed on the computer, it receives the connection point /mnt/userdata1 . However, this is not absolutely necessary, and it can be any mount point at all. In fact, if you connect it to another computer, it can easily become another mount point.

Since this path is determined by the operating system of the computer, you need to find this path on your computer (note that each time you connect the phone to the computer, it can be different, so you will need to do this every time).

From your question and path structure ( /mnt/userdata1 ) I assume that you are using Linux or some other version of unix. Therefore, you can run mount on your PC to see a list of installed devices. For example, here is 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) 

Pay attention to the last line in the output - this is my connected Android phone with an SD card installed on the computer. On macs, mount points are created in /Volumes instead of /mnt . In addition, ALEKS540 is a shortcut of my SD card, so it is installed in this way.

Inside the phone, it is still installed as /mnt/sdcard .

From an Android perspective, there can be three types of storage:

  • The internal memory is always installed under the device / on the device and contains everything except the SD card and USB drive below.
  • SD card - This is called "external storage" and is usually installed as /mnt/sd , but not always. Environment.getExternalStorageDirectory() will return the path to the connection point of the SD card.
  • USB storage - only supported on very few devices (supporting USB host mode for external storage). This will be installed somewhere under /mnt , but the exact location will be different. You will need to use the Android NDK to poll and repeat installed devices to find the one you need.
0
source

All Articles