Check if the SDCard is present, boolean is always true

前端 未结 7 1999
故里飘歌
故里飘歌 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 05:55

    Shouldn't it be:

    boolean isPresent = Environment.getExternalStorageState().equals(
       Environment.MEDIA_MOUNTED
    );
    

    As the documentation states for Environment.getExternalStorageState():

    Gets the current state of the primary "external" storage device.

    And for the Environment.MEDIA_MOUNTED-constant:

    getExternalStorageState() returns MEDIA_MOUNTED if the media is present and mounted at its mount point with read/write access.

    And this will work from API Level 1+

提交回复
热议问题