Get sdcard directory by adb

杀马特。学长 韩版系。学妹 提交于 2019-12-04 08:16:42

问题


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

回答1:


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



回答2:


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)




回答3:


Its better to use getExternalStorageDirectory() instead of System.getenv("EXTERNAL_STORAGE") This will give you external storage directory irrespective of device.



来源:https://stackoverflow.com/questions/9374628/get-sdcard-directory-by-adb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!