Back to project page ImageScanner.
The source code is released under:
Apache License
If you think the Android project ImageScanner listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.scanner.utils; //w ww. j a v a 2s . c om import java.io.File; import java.util.ArrayList; import android.content.Context; import android.database.Cursor; import android.graphics.Bitmap; import android.provider.MediaStore.Images.Media; import com.scanner.beans.GalleryFolderBean; public class ScannerUtils { /** * * get the folders which contain picture files; */ public static ArrayList<GalleryFolderBean> getGalleryFolder(Context context) { ArrayList<GalleryFolderBean> list = new ArrayList<GalleryFolderBean>(); ArrayList<String> folderList = new ArrayList<String>(); Bitmap bitmap; String folderName; String folderSize = ""; Cursor cursor = context.getContentResolver().query( Media.EXTERNAL_CONTENT_URI, null, null, null, null); while (cursor.moveToNext()) { byte[] data = cursor.getBlob(cursor.getColumnIndex(Media.DATA)); String imgUrl = new String(data, 0, data.length - 1); // localImageList.add(new LocalImageBean(path)); File file = new File(imgUrl); folderName = file.getParentFile().getName(); if (false == folderList.contains(folderName)) { String folderPath = file.getParentFile().getAbsolutePath(); folderSize = getGalleryBitmapsIn_A_Folder(folderPath).size() + ""; folderList.add(folderName); Bitmap bitmap_decode = BitmapUtils.decodeBitmapFromFile(imgUrl, 100, 100); bitmap = BitmapUtils.centerSquareScaleBitmap(bitmap_decode, 70); GalleryFolderBean bean = new GalleryFolderBean(bitmap, folderName, file.getParentFile().getAbsolutePath(), folderSize); list.add(bean); } } return list; } /** * get all the pictures in a certain folder * @param path * @return */ public static ArrayList<String> getGalleryBitmapsIn_A_Folder(String path) { ArrayList<String> list = new ArrayList<String>(); String tempPath; File file = new File(path); for (File imgFile : file.listFiles()) { tempPath = imgFile.getAbsolutePath(); if(isImgFile(tempPath)) list.add(0,tempPath); } return list; } /** * check if it is a picture file * @param name * @return */ public static boolean isImgFile(String name){ if(name.endsWith("jpg") || name.endsWith("jpeg") || name.endsWith("png") || name.endsWith("icon")){ return true; } return false; } }