简体   繁体   English

Android:外置SD卡的绝对位置

[英]Android: absolute location of External sd-card

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?" “有没有办法在Android中找到INTERNAL STORAGE DIRECTORYEXTERNAL STORAGE DIRECTORY(SDCARD)的绝对路径?”

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.. 请不要建议使用Environment.getExternalStorageDirectory因为它通常会返回内部存储路径,或者Android操作系统默认选择WHATEVER存储介质。

Any suggestions please? 有什么建议吗?

That's been asked before on SO, use the search. 之前已经问过SO,请使用搜索。 In short, 'external storage' is more like 'shared storage' and it may or may not be implemented by an actual SD card. 简而言之,“外部存储”更像是“共享存储”,它可能会或可能不会由实际的SD卡实现。 Some devices have an additional SD card, not used as external storage. 某些设备有一个额外的SD卡,不用作外部存储设备。 If that is what you are asking for, there is currently no public API for accessing its mount location, and it varies between devices. 如果这是您要求的,那么目前没有用于访问其安装位置的公共API,并且它在不同设备之间有所不同。 You can check /proc/mount to see what is currently mounted and go from there. 您可以检查/proc/mount以查看当前安装的内容并从那里开始。

This link is from the Android configuration guide. 此链接来自Android配置指南。 I assume it's recommend and is not required. 我认为这是推荐的,不是必需的。

https://source.android.com/devices/tech/storage/config-example.html https://source.android.com/devices/tech/storage/config-example.html

So, to get the SDCARD, you can just do. 所以,要获得SDCARD,你可以做到。

String storagePath = System.getenv("SECONDARY_STORAGE");

if (storagePath == null) {
    return null;
} else {
     String[] storagePathArray = storagePath.split(":");
     return storagePathArray[0];
}

EXTERNAL_STORAGE seems to be on everything on I own. EXTERNAL_STORAGE似乎是我自己的一切。

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). SECONDARY_STORAGE在我的LG GTab 8.3和我的三星Tab 2&3上定义,但不在我的Galaxy S(2.3)或我的戴尔Venue(4.3)上。 On Samsung devices it seems to contained multiple paths with the SD card first, thus the split. 在三星设备上,它似乎首先包含SD卡的多条路径,因此分割。

你应该用

Environment.getExternalStorageDirectory().getAbsolutePath()

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. 我认为/ storage / sdcard0 /用于内部sdcard,而/ storage / sdcard1 /用于外部sd卡,如果存在两个存储选项。 if you are checking a file is present either in any of sdcard or not you should check all possible paths. 如果您正在检查文件是否存在于任何SD卡中,则应检查所有可能的路径。

 String path;    
 if(new File("/storage/sdcard/yourpath").exist())
     {
        path="/storage/sdcard/yourpath";
     }
 else if(new File("/storage/sdcard0/yourpath").exists())
     {
        path="/storage/sdcard0/yourpath";
     }
 else if(new File("/storage/sdcard1/yourpath").exists())
     {
        path="/storage/sdcard1/yourpath";
     }

String path = ExternalStorageDirectoryPath +“/ foldername /”;

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: 在三星Galaxy Note 10.1 2014版SM-P600(我会假设同一年份的大多数其他三星Galaxy音符),“REAL”外部SD卡的完整路径是:

/storage/extSdCard/ /存储/ extSdCard /

I found mine using a terminal and did: 我发现我使用终端并且做了:

cd /storage/extSdCard/ 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. 然后,在卡片的根目录中,我使用“ls”命令列出文件,这样我就可以验证存储在其中的内容。 Thats how I found mine. 多数民众赞成我如何找到我的。 Hope it helps someone else. 希望它可以帮助别人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM