android获取相册文件夹DCIM的api
时间: 2023-11-16 08:06:16 浏览: 53
要获取相册文件夹DCIM的API可以通过使用Android的媒体库来实现。以下是获取相册文件夹DCIM的代码示例:
```java
public static List<String> getDCIMPhotos(Context context) {
List<String> photoList = new ArrayList<>();
String[] projection = new String[]{MediaStore.Images.Media.DATA};
String selection = MediaStore.Images.Media.DATA + " like ?";
String[] selectionArgs = new String[]{"%/DCIM/%"};
String orderBy = MediaStore.Images.Media.DATE_TAKEN + " DESC";
Cursor cursor = context.getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, selection, selectionArgs, orderBy);
if (cursor != null) {
while (cursor.moveToNext()) {
String photoPath = cursor.getString(cursor.getColumnIndex(projection[0]));
photoList.add(photoPath);
}
cursor.close();
}
return photoList;
}
```
通过调用该方法,你可以获取到相册文件夹DCIM中的所有图片。需要注意的是,代码中使用了MediaStore.Images.Media这个类来操作媒体库,需要在AndroidManifest.xml中添加读取媒体库的权限。