Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get sdcard directory by adb

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
like image 240
Paweł Avatar asked Feb 21 '12 08:02

Paweł


People also ask

How do I check storage on ADB?

Your first step to determining what's full is to execute in either a terminal or adb shell the command “df /sdcard” – this will display the disk space used by the internal SD. For purposes of this, the /sdcard mount point is all we're interested in, but if you want to see external space used you could do “df /sdcard2”.


2 Answers

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)

like image 64
John Deaux Avatar answered Oct 05 '22 12:10

John Deaux


If I've not misunderstood you, you're looking for something like:

emanuele@Nabucodonosor:~$ adb shell cd \$EXTERNAL_STORAGE
emanuele@Nabucodonosor:~$ adb shell ls \$EXTERNAL_STORAGE
emanuele@Nabucodonosor:~$ adb shell echo \$EXTERNAL_STORAGE
like image 26
Blackbelt Avatar answered Oct 05 '22 10:10

Blackbelt