[英]Android MediaStore.Files.getContentUri how to get a folder internal to the app
In my app, I am trying to build a image gallery to display the images taken using the app from a folder created within the app.在我的应用程序中,我试图构建一个图片库来显示使用该应用程序从应用程序中创建的文件夹中拍摄的图像。
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"
);
}
I am using the above code to get the files from the folder.我正在使用上面的代码从文件夹中获取文件。 However, the above code uses:
但是,上面的代码使用:
MediaStore.Files.getContentUri( "external" ),
the external directory.外部目录。 This displays the images in my DCIM/Camera folder of the phone.
这会显示我手机的 DCIM/Camera 文件夹中的图像。 When I tried to change this to an internal folder, I am not getting any images.
当我尝试将其更改为内部文件夹时,我没有收到任何图像。 I tried the following:
我尝试了以下方法:
File imageDestPath = new File(getApplicationContext().getFilesDir(), "cropped");
and used the imageDestPath
in并在其中使用了
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
I think I have not understood the MediaStore.Files.getContentUri part correctly.我想我没有正确理解 MediaStore.Files.getContentUri 部分。 When I attach the
imageDestPath
to a Toast, it displays the folder correctly.当我将
imageDestPath
附加到 Toast 时,它会正确显示文件夹。
When I tried to change this to an internal folder, I am not getting any images
当我尝试将其更改为内部文件夹时,我没有收到任何图像
MediaStore
has no access to those images, and getContentUri()
does not support internal storage . MediaStore
无法访问这些图像,并且getContentUri()
不支持内部存储。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.