1

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

Community
  • 1
  • 1
Hanzo
  • 1,839
  • 4
  • 30
  • 51

2 Answers2

4

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.

Amit Joki
  • 58,320
  • 7
  • 77
  • 95
Hsin-Hsiang
  • 411
  • 1
  • 3
  • 13
-1

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;
}
Uttam Suthar
  • 106
  • 6
  • Thank you for this code snippet, which may provide some immediate help. A proper explanation [would greatly improve](//meta.stackexchange.com/q/114762) its educational value by showing *why* this is a good solution to the problem, and would make it more useful to future readers with similar, but not identical, questions. Please [edit] your answer to add explanation, and give an indication of what limitations and assumptions apply. – Toby Speight Jul 03 '17 at 10:49