Android 扫描SD卡根目录的所有文件夹和音乐文件
作者:互联网
public static List<String> musicPaths = null;
public String getSDPath()
{
File sdDir = null;
boolean sdCardExist = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED); // 判断sd卡是否存在
if (sdCardExist)
{
sdDir = Environment.getExternalStorageDirectory();
}
return sdDir != null ? sdDir.toString() : "";
}
private List<String> getMusicList()
{
musicPaths.clear();
try
{
File file = new File(getSDPath());
File[] files = file.listFiles();
for(File theFile : files)
{
if(theFile.isDirectory())
{
musicPaths.add(theFile.getPath());
}
}
for(File theFile : files)
{
if(theFile.isFile())
{
if(matchMusicFile(theFile.getPath()))
{
musicPaths.add(theFile.getPath());
}
}
}
}
catch (Exception e)
{
return main.musicPaths;
}
return main.musicPaths;
}
标签:Environment,音乐文件,sdDir,theFile,File,根目录,Android,null,musicPaths 来源: https://blog.51cto.com/u_15298588/3034407