Android 扫描SD卡根目录的所有文件夹和音乐文件

public static List 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 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;
}

 

你可能感兴趣的:(Andorid)