Get sdcard directory by adb

Paweł picture Paweł · Feb 21, 2012 · Viewed 58.2k times · Source

I am making an application, which pulls files(Saved by android app) from the device sdcard by adb. The problem is that different devices, have various sdcard directories

i.e:

  • sdcard
  • sdcard/external_sd

Firstly I invented following solution:

  1. run adb shell
  2. ls
  3. Check if dir "sdcard" exists
  4. If yes run sdcard/ ls and check if external_sd exists
  5. return value.

But the problem is that I have two samsung devices GT-I9100 and GT-I9000 and both have a directory sdcard/external_sd. When I am checking System.getenv("EXTERNAL_STORAGE") one returns sdcard and another sdcard/external_sd. I need to pull file which was previously saved to System.getenv("EXTERNAL_STORAGE").

So the question is: is there any command to get sdcard directory directly from adb, without access to Android code?

Or maybe I can start activity with adb's am start, and get return value? Is this possible?

EDIT: Found the solution:

adb shell echo $EXTERNAL_STORAGE

Answer

John Deaux picture John Deaux · Mar 22, 2015

For what its worth - using the $EXTERNAL_STORAGE variable can give you misleading results. I have a HP Slate tablet here, which has the EXTERNAL_STORAGE variable set to /storage/sdcard0 . However when using df (disk free) command on shell, or even the mount command to display free space or mounts, the following becomes obvious:

shell@android:/ $ df
Filesystem             Size   Used   Free   Blksize
/dev                  452.7M  36.0K  452.7M   4096
/mnt/asec             452.7M  0.0 K  452.7M   4096
/mnt/obb              452.7M  0.0 K  452.7M   4096
/system               629.9M  468.5M  161.5M   4096
/data                 5.7 G  2.3 G  3.5 G   4096
/cache                435.9M  16.4M  419.5M   4096
/storage/sdcard0      5.7 G  2.3 G  3.5 G   4096
/mnt/external_sd      29.3G  64.0K  29.3G   32768

so, the external sd card is in fact /mnt/external_sd, instead of the value EXTERNAL_STORAGE returns(which is the internal storage)