我正在尝试扫描 SD 卡中的所有 .mp3 文件并保存其名称。这是负责此的代码片段。1.我做错了什么?1. SD 卡 /mnt/sdcard 或 /sdcard 的正确路径是哪个?
public class PlayerActivity extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.player_activity);
}
public class SongsManager
{
// SDCard Path
//final String MEDIA_PATH = new String(MediaStore.Audio.Media.getContentUri("external").toString());
private ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
public SongsManager()
{
}
public ArrayList<HashMap<String, String>> getPlayList()
{
// File home = new File(MEDIA_PATH);
File home = Environment.getExternalStorageDirectory();
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;
}
class FileExtensionFilter implements FilenameFilter
{
public boolean accept(File dir, String name)
{
return (name.endsWith(".mp3") || name.endsWith(".MP3"));
}
}
}
}
提前致谢。