安卓获取相册列表的实现代码
时间: 2023-06-03 16:07:33 浏览: 143
android 获取相册列表的实现源码
5星 · 资源好评率100%
以下是Android获取相册列表的示例代码:
```
private ArrayList<String> getGalleryPhotos() {
ArrayList<String> galleryList = new ArrayList<>();
final String[] columns = {MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID};
final String orderBy = MediaStore.Images.Media.DATE_TAKEN;
Cursor imageCursor = getContext().getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
columns, null, null, orderBy + " DESC");
if (imageCursor != null && imageCursor.moveToFirst()) {
while (imageCursor.moveToNext()) {
String path = imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Images.Media.DATA));
galleryList.add(path);
}
imageCursor.close();
}
return galleryList;
}
```
阅读全文