System.getenv(“SECONDARY_STORAGE”) return null on some devices

…衆ロ難τιáo~ 提交于 2019-12-11 07:41:29

问题


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


回答1:


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.




回答2:


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;
}


来源:https://stackoverflow.com/questions/26652015/system-getenvsecondary-storage-return-null-on-some-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!