Android – Get/access file(path) from SD-card

By -

Problem: How do we get/access file from SD-card?

File externalStorage = Environment.getExternalStorageDirectory();
String strUri = externalStorage.getAbsolutePath()+"/"+"test.mp3";
System.out.println("============> Hello => "+strUri);

Output:Output of Environment.getExternalStorageDirectory() can be either /sdcard or /mnt/sdcard. As i have tested it, it returns the below output on different brand device:

In Samsung Galaxy 3 => /mnt/sdcard/test.mp3
In HTC Hero => /sdcard/test.mp3

Paresh Mayani

Lazy android developer, exploring the horizon of android development since 7 years, currently working as a Technical Lead - Android at Simform Solutions, India. Former Application Architect at KarConnect. He is the Head/Organizer of Google Developers Group (GDG), Ahmedabad

Loading Facebook Comments ...
Loading Disqus Comments ...