Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get file path from sd card in android

Tags:

android

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

please assist me.

like image 766
M.A.Murali Avatar asked May 02 '11 14:05

M.A.Murali


People also ask

What is the file path for SD card in Android?

The external storage was often a “Secure Digital” (or SD) card. On devices without a physical SD Card, it is often emulated. Traditionally the SD Card is referenced via the file path “/sdcard” for consistency.


2 Answers

You can get the path of sdcard from this code:

File extStore = Environment.getExternalStorageDirectory(); 

Then specify the foldername and file name

for e.g:

"/LazyList/"+serialno.get(position).trim()+".jpg" 
like image 64
Jaydeep Khamar Avatar answered Oct 03 '22 05:10

Jaydeep Khamar


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.

like image 34
AnV Avatar answered Oct 03 '22 05:10

AnV