I'm trying to get a List of external storages on android devices and in some devices the instruction System.getenv("SECONDARY_STORAGE");
returns null
although the sd card is mounted in the device (4.1.1).
I'm using the Dimitriy solution to do this and works fine but in some devices I'm having this problem.
Someone know in what cases System.getenv("SECONDARY_STORAGE")
can return null
?
Thanks a lot
In my experiments,
Some old HTC devices will returns null when you call System.getenv("SECONDARY_STORAGE")
I found that the actual microSD path in such devices is be mounted in
/storage/sdcard0/ext_sd/
/sdcard2/
/mnt/sdcard/ext_sd/
Due to external storage environment variable is defined by phone manufacturers.
We don't have a API to exactly get the microSD path.
Here is the solution.
try it...
First get All files in list
var file=new Java.IO.File("storage/");
var listOfStorages=file.ListFiles();
var isSDPresent=false;
if(listOfStorages[1].Name.Containes("emulated")||listOfStorages[0].Name.Containes("-"))
{
isSDPresent=true;
}