Android 获取图片文件列表
原创
©著作权归作者所有:来自51CTO博客作者碼雲的原创作品,请联系作者获取转载授权,否则将追究法律责任
public static ArrayList<HashMap<String, String>> getImageList(Context context) {
ArrayList<HashMap<String , String>> hashmapList = new ArrayList<HashMap<String,String>>() ;
String[] columns = {.TITLE, .DATA};
Cursor cursor = context.getContentResolver().query(.EXTERNAL_CONTENT_URI, columns, null, null, .DEFAULT_SORT_ORDER);
if (cursor == null) return hashmapList;
if (cursor.moveToFirst()) {
int titleIndex = cursor.getColumnIndex(.TITLE);
int dataIndex = cursor.getColumnIndex(.DATA);
do {
String szTitle = cursor.getString(titleIndex);
String szPath = cursor.getString(dataIndex);
HashMap<String, String> hashMap = new HashMap<String, String>();
hashMap.put(.TITLE, szTitle);
hashMap.put(.DATA, szPath);
hashmapList.add(hashMap);
} while (cursor.moveToNext());
}
cursor.close();
return hashmapList;
}