how to get file path from sd card in android

后端 未结 7 987
旧时难觅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:00

    Environment.getExternalStorageDirectory() will NOT return path to micro SD card Storage.

    how to get file path from sd card in android

    By sd card, I am assuming that, you meant removable micro SD card.

    In API level 19 i.e. in Android version 4.4 Kitkat, they have added File[] getExternalFilesDirs (String type) in Context Class that allows apps to store data/files in micro SD cards.

    Android 4.4 is the first release of the platform that has actually allowed apps to use SD cards for storage. Any access to SD cards before API level 19 was through private, unsupported APIs.

    Environment.getExternalStorageDirectory() was there from API level 1

    getExternalFilesDirs(String type) returns absolute paths to application-specific directories on all shared/external storage devices. It means, it will return paths to both internal and external memory. Generally, second returned path would be the storage path for microSD card (if any).

    But note that,

    Shared storage may not always be available, since removable media can be ejected by the user. Media state can be checked using getExternalStorageState(File).

    There is no security enforced with these files. For example, any application holding WRITE_EXTERNAL_STORAGE can write to these files.

    The Internal and External Storage terminology according to Google/official Android docs is quite different from what we think.

提交回复
热议问题