Check if the SDCard is present, boolean is always true

前端 未结 7 2000
故里飘歌
故里飘歌 2020-11-29 05:42

In my splash screen, I want to check if the phone has a SDCard. The Boolean statement is beneath:

    Boolean isSDPresent = android.os.Environment.getExterna         


        
7条回答
  •  清酒与你
    2020-11-29 06:01

    We have two memory status. One is Internal memory card and other is external sd card. It depends upon device manufactures how they have manufactured the memory card path. So if you are checking for sd card availability then it may return true in both cases due to internal memory. So go for this method:

    File[] listOfInternalAndExternalStorage=context.getExternalFilesDirs(null); 
       if(listOfInternalAndExternalStorage.length>=2){
         // it contains sd card
       }
    

    above code will check if listOfInternalAndExternalStorage is more than one then it has external storage, otherwise it does not contain sd card.

提交回复
热议问题