public List<ImageItem> getAllImages(Context context) { List<ImageItem> data = new ArrayList<>(); int id = 0; Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null, null, null); if (cursor.moveToFirst()) { do { String title = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.TITLE)); String url = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)); ImageItem images = new ImageItem(id, title, url); data.add(images); id++; } while (cursor.moveToNext()); cursor.close(); } return data; }
时间: 2023-02-19 15:03:33 浏览: 83
数据绑定List学习
很高兴为您提供帮助。这里是获取所有图片的代码:使用ContentResolver查询MediaStore.Images.Media.EXTERNAL_CONTENT_URI,遍历查询结果,将查询到的图片信息封装到ImageItem中,最后返回ImageItem的列表。
阅读全文