如何使用媒体商店加载所有图像?
How to load all the Images using Media Store?
我想加载用户设备中存在的所有图像。我知道图像可以使用 Media Store 加载,但对我来说最大的缺点是存在于具有 .nomedia
文件的文件夹中的图像不是 loaded/retrieved 使用 Media Store。
是否有使用 Media Store 或不使用 Media Store 的有效方法来加载 Android 设备中存在的所有图像,而不管其父文件夹是否具有 .nomedia
文件?
这就是我加载父目录没有 .nomedia
文件的图像的方式:
public void getImages(Context context) {
File Image_File;
final String[] columns = {MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID};
String orderBy = MediaStore.Images.Media.DATE_MODIFIED ;
Cursor cursor = context.getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
null, orderBy);
if (cursor != null)
{
cursor.moveToFirst();
final int dataColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
while (cursor.moveToNext()) {
Image_File = new File(cursor.getString(dataColumnIndex));
//Add the Image to the list
}
}
}
我知道我可以扫描每个文件夹并检查其中是否存在图像,但这会花费很多时间。
MediaStrore 不扫描包含 .nomedia
文件的目录。
所以你不能要求 MediaStore 传送它们。
您确实必须创建自己的媒体商店。
我想加载用户设备中存在的所有图像。我知道图像可以使用 Media Store 加载,但对我来说最大的缺点是存在于具有 .nomedia
文件的文件夹中的图像不是 loaded/retrieved 使用 Media Store。
是否有使用 Media Store 或不使用 Media Store 的有效方法来加载 Android 设备中存在的所有图像,而不管其父文件夹是否具有 .nomedia
文件?
这就是我加载父目录没有 .nomedia
文件的图像的方式:
public void getImages(Context context) {
File Image_File;
final String[] columns = {MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID};
String orderBy = MediaStore.Images.Media.DATE_MODIFIED ;
Cursor cursor = context.getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
null, orderBy);
if (cursor != null)
{
cursor.moveToFirst();
final int dataColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
while (cursor.moveToNext()) {
Image_File = new File(cursor.getString(dataColumnIndex));
//Add the Image to the list
}
}
}
我知道我可以扫描每个文件夹并检查其中是否存在图像,但这会花费很多时间。
MediaStrore 不扫描包含 .nomedia
文件的目录。
所以你不能要求 MediaStore 传送它们。
您确实必须创建自己的媒体商店。