【发布时间】:2021-08-04 15:46:43
【问题描述】:
我在Pictures 目录中有一个自定义文件夹,例如Pictures/MyFolder。它在MyFolder 中有图像。以下是仅在 MyFolder 文件夹上使用 ContentResolver 查询图像的方法。
我试过了
Cursor mediaCursor = context.getContentResolver().query(
MediaStore.Files.getContentUri("external"),
null,
MediaStore.MediaColumns.RELATIVE_PATH + " like ? ",
new String[]{"%MyFolder%"},
null);
但它也包含其他文件。还是内容解析器的替代品?
【问题讨论】:
-
It has images in MyFolder.你应该开始告诉谁把这些图片放在那里以及如何放在那里。 -
But it contains other files also.什么意思?其他应用程序是否也将图像放在那里?并且使用 getContentResolver 是无关紧要的。您正在查询 MediaStore。 -
感谢@blackapps 的回复,我使用
File imageFolder = new File(Environment.DIRECTORY_PICTURES, context.getString(R.string.app_name)); ContentValues newImage = new ContentValues(); newImage.put(MediaStore.MediaColumns.RELATIVE_PATH, imageFolder.toString()); context.getContentResolver().insert(collection, newImage);将图像放在了那个特定的文件夹中
标签: android android-gallery mediastore android-contentresolver