how to get file path from sd card in android

后端 未结 7 974
旧时难觅i
旧时难觅i 2020-11-28 09:00

hi all i have mp3 files in sd card. how to get file path of mp3 song from sd card.

please assist me.

相关标签:
7条回答
  • 2020-11-28 10:01

    As some people indicated, the officially accepted answer does not quite return the external removable SD card. And i ran upon the following thread that proposes a method I've tested on some Android devices and seems to work reliably, so i thought of re-sharing here as i don't see it in the other responses:

    http://forums.androidcentral.com/samsung-galaxy-s7/668364-whats-external-sdcard-path.html

    Kudos to paresh996 for coming up with the answer itself, and i can attest I've tried on Samsung S7 and S7edge and seems to work.

    Now, i needed a method that returned a valid path where to read files, and that considered the fact that there might not be an external SD, in which case the internal storage should be returned, so i modified the code from paresh996 to this :

    File getStoragePath() {
        String removableStoragePath;
        File fileList[] = new File("/storage/").listFiles();
        for (File file : fileList) {
           if(!file.getAbsolutePath().equalsIgnoreCase(Environment.getExternalStorageDirectory().getAbsolutePath()) && file.isDirectory() && file.canRead()) {
                return file;
            }
        }
        return Environment.getExternalStorageDirectory();
    }
    
    0 讨论(0)
提交回复
热议问题