I\'m trying to make an mp3 player app, and when I run it from my phone it only reads MP3\'s that are present on the SD card itself. It does not read any MP3\'s from the subf
File home = new File(MEDIA_PATH);
Then
walkdir(home);
WalkDir method
public void walkdir(File dir) {
String Pattern = ".mp3";
File listFile[] = dir.listFiles();
if (listFile != null) {
for (int i = 0; i < listFile.length; i++) {
if (listFile[i].isDirectory()) {
walkdir(listFile[i]);
} else {
if (listFile[i].getName().endsWith(Pattern)){
//Do what ever u want
// add the path to hash map
}
}
}
}
}
Even better use enhanced for loop as suggested by blackbelt @
Delete only .jpg files from folder in android
Instead of deleting add the path to the hahsmap
There is the MusicRetriever example in the Android SDK. It uses a ContentResolver.