【发布时间】:2020-11-20 16:37:34
【问题描述】:
在我的应用中,我正在尝试构建一个图片库,以显示使用该应用从应用内创建的文件夹中拍摄的图像。
public Loader<Cursor> onCreateLoader(int id, @Nullable Bundle args) {
// File imageDestPath = new File(getApplicationContext().getFilesDir(), "cropped");
String[] projection = {
MediaStore.Files.FileColumns._ID,
MediaStore.Files.FileColumns.DATE_ADDED,
MediaStore.Files.FileColumns.DATA,
MediaStore.Files.FileColumns.MEDIA_TYPE
};
String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
+ MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE
+ " OR "
+ MediaStore.Files.FileColumns.MEDIA_TYPE + " = "
+ MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO;
return new CursorLoader( this,
MediaStore.Files.getContentUri( "external" ),
projection,
selection,
null,
MediaStore.Files.FileColumns.DATE_ADDED + " DESC"
);
}
我正在使用上面的代码从文件夹中获取文件。但是,上面的代码使用:
MediaStore.Files.getContentUri( "external" ),
外部目录。这将显示手机的 DCIM/Camera 文件夹中的图像。当我尝试将其更改为内部文件夹时,我没有收到任何图像。我尝试了以下方法:
File imageDestPath = new File(getApplicationContext().getFilesDir(), "cropped");
并在
中使用了imageDestPath
MediaStore.Files.getContentUri( imageDestPath ), //not working
MediaStore.Files.getContentUri( "internal" ), //not displaying any images - no error
MediaStore.Files.getContentUri( getFilesDir.getName() ), //not displaying any images - no error
MediaStore.Files.getContentUri( getFilesDir()+"cropped" ), //not displaying any images - no error
我想我没有正确理解 MediaStore.Files.getContentUri 部分。当我将imageDestPath 附加到 Toast 时,它会正确显示文件夹。
【问题讨论】:
标签: android mediastore