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