Find location of a removable SD card

前端 未结 22 2571
南方客
南方客 2020-11-21 11:32

Is there an universal way to find the location of an external SD card?

Please, do not be confused with External Storage.

Environment.getExternalStorage

22条回答
  •  囚心锁ツ
    2020-11-21 11:56

    I try all solutions inside this topic on this time. But all of them did not work correctly on devices with one external (removable) and one internal (not-removable) cards. Path of external card not possible get from 'mount' command, from 'proc/mounts' file etc.

    And I create my own solution (on Paulo Luan's):

    String sSDpath = null;
    File   fileCur = null;
    for( String sPathCur : Arrays.asList( "ext_card", "external_sd", "ext_sd", "external", "extSdCard",  "externalSdCard")) // external sdcard
    {
       fileCur = new File( "/mnt/", sPathCur);
       if( fileCur.isDirectory() && fileCur.canWrite())
       {
         sSDpath = fileCur.getAbsolutePath();
         break;
       }
    }
    fileCur = null;
    if( sSDpath == null)  sSDpath = Environment.getExternalStorageDirectory().getAbsolutePath();
    

提交回复
热议问题