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

By -

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

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

CEO & Co-Founder at SolGuruz® | Organiser @ GDG Ahmedabad | Top 0.1% over StackOverflow | 15+ years experienced Tech Consultant | Helping startups with Custom Software Development

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