Android:外部 SD 卡的绝对位置
我有一个非常简单的问题,但到目前为止我无法找到这个问题的答案。 “有没有办法在Android中找到INTERNAL STORAGE DIRECTORY
和EXTERNAL STORAGE DIRECTORY(SDCARD)
的绝对路径?”
请不要建议使用 Environment.getExternalStorageDirectory
因为它通常返回内部存储的路径或 Android 操作系统默认选择的存储介质。
有什么建议吗?
I have a very simple question but so far I am unable to find an answer of this question. "Is there any way of finding the absolute path of INTERNAL STORAGE DIRECTORY
and EXTERNAL STORAGE DIRECTORY(SDCARD)
in Android?"
Please don't recommend using Environment.getExternalStorageDirectory
since it usually returns the path for internal storage or WHATEVER storage media is selected as default by the Android operating system..
Any suggestions please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
之前有人问过这个问题,请使用搜索。简而言之,“外部存储”更像是“共享存储”,它可能会也可能不会由实际的 SD 卡实现。有些设备有一个额外的 SD 卡,不用作外部存储。如果这就是您所要求的,则当前没有用于访问其安装位置的公共 API,并且它因设备而异。您可以检查 /proc/mount 来查看当前安装的内容并从那里开始。
That's been asked before on SO, use the search. In short, 'external storage' is more like 'shared storage' and it may or may not be implemented by an actual SD card. Some devices have an additional SD card, not used as external storage. If that is what you are asking for, there is currently no public API for accessing its mount location, and it varies between devices. You can check
/proc/mount
to see what is currently mounted and go from there.此链接来自 Android 配置指南。我认为这是推荐的而不是必需的。
https://source.android.com/devices/tech/storage/config -example.html
因此,要获取 SDCARD,您就可以这样做。
EXTERNAL_STORAGE 似乎是我自己的一切。
SECONDARY_STORAGE 是在我的 LG GTab 8.3 和我的 Samsung Tab 2&3 上定义的,但在我的 Galaxy S (2.3) 或我的 Dell Venue (4.3) 上没有定义。在三星设备上,它似乎首先包含 SD 卡的多个路径,因此进行了拆分。
This link is from the Android configuration guide. I assume it's recommend and is not required.
https://source.android.com/devices/tech/storage/config-example.html
So, to get the SDCARD, you can just do.
EXTERNAL_STORAGE seems to be on everything on I own.
SECONDARY_STORAGE was defined on my LG GTab 8.3 and my Samsung Tab 2&3, but not on my Galaxy S (2.3) or my Dell Venue (4.3). On Samsung devices it seems to contained multiple paths with the SD card first, thus the split.
你应该使用
You should use
在三星 Galaxy Note 10.1 2014 版 SM-P600(我假设大多数其他三星 Galaxy Notes 同型号)上,“真实”外部 SD 卡的完整路径是:
/storage/extSdCard/
我发现我的使用终端并执行:
cd /storage/extSdCard/
然后进入卡的根目录后,我使用“ls”命令列出文件,这样我就可以验证存储的内容在它上面。我就是这样找到我的。希望它对其他人有帮助。
On Samsung Galaxy Note 10.1 2014 edition SM-P600 (and I would assume most other samsung galaxy notes of the same vintage), the full path to the "REAL" external sdcard, is this:
/storage/extSdCard/
I found mine using a terminal and did:
cd /storage/extSdCard/
then once in the root of the card, I used the "ls" command to list files, so I could verify what was stored on it. Thats how I found mine. Hope it helps someone else.
我认为 /storage/sdcard0/ 用于内部 SD 卡,而 /storage/sdcard1/ 用于外部 SD 卡(如果存在两个存储选项)。
如果您要检查某个文件是否存在于任何 SD 卡中,您应该检查所有可能的路径。
I think /storage/sdcard0/ is used for internal sdcard and /storage/sdcard1/ is used for external sd card if there are two storage option present.
if you are checking a file is present either in any of sdcard or not you should check all possible paths.
String path=ExternalStorageDirectoryPath + "/文件夹名称/";
String path=ExternalStorageDirectoryPath + "/foldername/";