Android 讀取SD卡中相應文件夾下的圖片

public class SDcardFileUtils {
   /**
    * path 指的是SD卡中存放圖片的文件夾
    * @param path
    * @return
     */
public static String SD = Environment.getExternalStorageDirectory().getPath()+"";
String path = SD + 存放圖片的文件夾 public static List<String> getImagePathFromSD(String path) { List<String> picList = new ArrayList<String>(); File mfile = new File(path); if (!mfile.exists()) { return picList; } File[] files = mfile.listFiles(); for (int i = 0; i < files.length; i++) { File file = files[i]; if (checkIsImageFile(file.getPath())) { picList.add(file.getPath()); } } return picList; } private static boolean checkIsImageFile(String fName) { boolean isImageFile = false; String FileEnd = fName.substring(fName.lastIndexOf(".") + 1, fName.length()).toLowerCase(); if (FileEnd.equals("jpg") || FileEnd.equals("png") || FileEnd.equals("gif") || FileEnd.equals("bmp")) { isImageFile = true; } else { isImageFile = false; } return isImageFile; }}

發佈了74 篇原創文章 · 獲贊 45 · 訪問量 16萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章