How to access all mp3 files from all the subfolders in the sdcard?

爱⌒轻易说出口 提交于 2019-11-28 01:41:51

There is the MusicRetriever example in the Android SDK. It uses a ContentResolver.

Raghunandan
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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!