Android: absolute location of external SD card

I have a very simple question, but so far I can not find the answer to this question. "Is there a way to find the absolute path of INTERNAL STORAGE DIRECTORY and EXTERNAL STORAGE DIRECTORY(SDCARD) in Android?"

Using Environment.getExternalStorageDirectory not recommended, as it usually returns the path for internal storage, or the default media for WHATEVER is Android.

Any suggestions please?

+6
source share
6 answers

This is previously defined in SO, use the search. In short, “external storage” is more like “shared storage”, and it may or may not be implemented using a real SD card. Some devices have an additional SD card, which is not used as external storage. If this is what you are asking for, there is currently no open API to access its mount location, and it is device dependent. You can check /proc/mount to see what is currently installed and from there.

+5
source

This link is taken from the Android setup guide. I assume this is recommended and not required.

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

So, to get the sdcard, you can just do.

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

EXTERNAL_STORAGE is like everything I have.

SECONDARY_STORAGE was defined on my LG GTab 8.3 and my Samsung Tab 2 and 3, but not on my Galaxy S (2.3) or in my Dell place (4.3). On Samsung devices, it seems that at first there were several paths with an SD card, so a split.

+2
source

You have to use

 Environment.getExternalStorageDirectory().getAbsolutePath() 
+1
source

I think that / storage / sdcard0 / is used for the internal SD card and / storage / sdcard1 / is used for the external SD card if there are two storage options. if you are checking a file, either present on any of the SD cards or not, you should check all possible paths.

  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"; } 
0
source

String path = ExternalStorageDirectoryPath + "/ foldername /";

0
source

In the release of the Samsung Galaxy Note 10.1 2014 SM-P600 (and I would suggest that most of Samsung's other galactic notes come from the same crop), the full path to an external REAL SD card is this:

/ storage / extSdCard /

I found mine using the terminal and did:

cd / storage / extSdCard /

and then once at the root of the map, I used the "ls" command to display the files, so I could check what was saved on it. This is how I found mine. Hope this helps someone else.

0
source

Source: https://habr.com/ru/post/896275/


All Articles