简体   繁体   English

Android MediaStore.Files.getContentUri 如何获取应用程序内部的文件夹

[英]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.

相关问题 MediaStore.Files.getContentUri("external") 不再返回文档文件(word、pdf、excel、...) - Document files (word, pdf, excel,...) are no longer returned from MediaStore.Files.getContentUri("external") 如何使用MediaStore获取存储在android的内部存储和外部存储中的所有音乐文件? - How to get all music files stored in internal storage and external storage in android using MediaStore? android MediaPlayer res原始文件夹getContentUri - android MediaPlayer res raw folder getContentUri 如何使用Android中的MediaStore.Files从内部和外部存储中获取所有.pdf文件 - How can I get all .pdf files from Internal as well as External storage using MediaStore.Files in Android 如何设置 MEDIASTORE 以从 android 上的特定文件夹获取图像 - how to set MEDIASTORE to get image from specific folder on android 如何使用 MediaStore Android 获取文件夹中的项目数 - How to get Count of Items in a Folder using MediaStore Android 如何在 android 工作室中使用 MediaStore Api 在 android 11 中获取特定文件夹,如 WhatsApp (.Status) 文件夹 - How to get specific folder like WhatsApp (.Status) folder in android 11 using MediaStore Api in android studio Android如何获取MediaStore的路径? - Android how to get path of mediastore? Android MediaStore 获取不同的音乐文件文件夹 - Android MediaStore get distinct folders of music files 如何在Android中获取内部内存文件的FileInputStream? 该文件位于我的应用程序空间中的自定义文件夹中 - How to get FileInputStream for internal memory files in Android ? The file is in my custom folder made in application space
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM