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;
}

 

上一篇:.net core 将图片存入environment.WebRootPath 后台服务时 对于图片的访问


下一篇:David Silver--deep RL--Lesson1