问题描述
我正在制作一个应用程序,它通过adb从设备sdcard中提取文件(由android应用程序保存)。
问题是不同的设备具有不同的sdcard目录
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
即:
- sdcard
- sdcard / external_sd
首先,我发明了以下解决方案:
Firstly I invented following solution:
- 运行adb shell
- ls
- 检查目录 sdcard存在
- 如果是,则运行sdcard / ls并检查external_sd是否存在
- 返回值。
- run adb shell
- ls
- Check if dir "sdcard" exists
- If yes run sdcard/ ls and check if external_sd exists
- return value.
但是问题是我有两个三星设备 GT-I9100
和 GT-I9000
都具有目录 sdcard / external_sd
。当我检查 System.getenv( EXTERNAL_STORAGE)
时,一个返回 sdcard
,另一个返回 sdcard / external_sd
。我需要提取以前保存到 System.getenv( EXTERNAL_STORAGE)
的文件。
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")
.
或者也许我可以以adb的am start开始活动,并获得返回
值?这可能吗?
Or maybe I can start activity with adb's am start, and get return value? Is this possible?
编辑:
找到了解决方案:
Found the solution:
adb shell echo $EXTERNAL_STORAGE
推荐答案
对于它的价值是什么-使用$ EXTERNAL_STORAGE变量可以使您产生误导的结果。
我这里有一个HP Slate平板电脑,其EXTERNAL_STORAGE变量设置为/ storage / sdcard0。
但是,在外壳上使用df(无磁盘)命令,甚至使用mount命令显示可用空间或装载时,以下内容将变得显而易见:
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
因此,外部sd卡实际上是/ mnt / external_sd,而不是EXTERNAL_STORAGE返回的值(内部存储)
so, the external sd card is in fact /mnt/external_sd, instead of the value EXTERNAL_STORAGE returns(which is the internal storage)
这篇关于通过adb获取sdcard目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!