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

 

上一篇:使用docker容器进行项目开发


下一篇:Python连接MYSQL