查询 Mediastore 以查找在应用程序外部创建的文件 returns 无

Querying Mediastore for a file created outside the App returns nothing

正在查询 MediaStore.Downloads 通过设备资源管理器上传的文件(因此在应用程序外部创建)returns 没有。

如果文件是由应用程序通过 .insert 方法创建的,则按预期方式查询 returns 文件。

这是某种权限问题吗?

文件位置= \Download\MyApp\MyFile.csv

        String selection = MediaStore.Downloads.RELATIVE_PATH + " LIKE ? ";
        // appfoldername = "MyApp"
        String[] selectionArgs = new String[]{
                '%' + Environment.DIRECTORY_DOWNLOADS + File.separator + appfoldername + '%'
                 };

        Cursor cursor  = resolver.query(MediaStore.Downloads.EXTERNAL_CONTENT_URI,
                new String[] {MediaStore.MediaColumns.RELATIVE_PATH, MediaStore.MediaColumns._ID, MediaStore.MediaColumns.DISPLAY_NAME, MediaStore.MediaColumns.MIME_TYPE}, selection, selectionArgs, null);

引用 the documentation:

If your app wants to access a file within the MediaStore.Downloads collection that your app didn't create, you must use the Storage Access Framework. To learn more about how to use this framework, see the guide on how to access documents and other files.