我想创建一个歌曲列表和他的路径。我写了这段代码,但是当我尝试创建列表时应用程序崩溃了。从文件中获取列表时出错。我怎样才能获得歌曲的路径?
File f = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
Toast.makeText(this, f.toString(), Toast.LENGTH_LONG).show();
if (f.listFiles().length > 0) {
for (File file : f.listFiles(new FileExtensionFilter())) {
Map<String, String> song = new HashMap<String, String>();
song.put("songTitle", file.getName().substring(0, (file.getName().length() - 4)));
song.put("songPath", file.getPath());
songsList.add(song);
Toast.makeText(this, song.toString(), Toast.LENGTH_LONG).show();
}
}