我已經有這個代碼...但我想搜索也通過子文件夾,而不是隻搜索槽sdcard.sorry爲我的英語;) 感謝幫助,vinzenz如何找到SDCard上的所有音頻文件(eclipse,安卓)
public class SongsManager {
// SDCard Path
final String MEDIA_PATH = new String("/sdcard/");
private ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
// Constructor
public SongsManager(){
**strong text**
}
/**
* Function to read all mp3 files from sdcard
* and store the details in ArrayList
* */
public ArrayList<HashMap<String, String>> getPlayList(){
File home = new File(MEDIA_PATH);
if (home.listFiles(new FileExtensionFilter()).length > 0) {
for (File file : home.listFiles(new FileExtensionFilter())) {
HashMap<String, String> song = new HashMap<String, String>();
song.put("songTitle", file.getName().substring(0, (file.getName().length() - 4)));
song.put("songPath", file.getPath());
// Adding each song to SongList
songsList.add(song);
}
}
// return songs list array
return songsList;
}
}
感謝一個很好的答案,本書雖然該方法managedQuery已棄用,請問您可以更新此答案嗎? – Marcus
而不是已棄用的managedQuery(),可以使用具有相同參數的getContentResolver()。query()。 – San