其他分享
首页 > 其他分享> > Android 获取图片文件列表

Android 获取图片文件列表

作者:互联网

public static ArrayList<HashMap<String, String>> getImageList(Context context) {
	ArrayList<HashMap<String , String>> hashmapList = new ArrayList<HashMap<String,String>>() ;
	String[] columns = {MediaStore.Images.Media.TITLE, MediaStore.Images.Media.DATA};
	Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null, null, MediaStore.Images.Media.DEFAULT_SORT_ORDER);
	if (cursor == null) return hashmapList;

	if (cursor.moveToFirst()) {
		int titleIndex = cursor.getColumnIndex(MediaStore.Images.Media.TITLE);
		int dataIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
		do {
			String szTitle = cursor.getString(titleIndex);
			String szPath = cursor.getString(dataIndex);

			HashMap<String, String> hashMap = new HashMap<String, String>();
			hashMap.put(MediaStore.Images.Media.TITLE, szTitle);
			hashMap.put(MediaStore.Images.Media.DATA, szPath);
			hashmapList.add(hashMap);
		} while (cursor.moveToNext());
	}
	cursor.close();
	return hashmapList;
}

 

标签:hashMap,Media,列表,cursor,获取,Images,Android,MediaStore,hashmapList
来源: https://blog.51cto.com/u_15298588/3034049