如何获取存储在使用 context.getDir(directoryName, Context.MODE_PRIVATE) 创建的文件夹中的文件的 URI?
How to get the URI of a file stored in a folder created with context.getDir(directoryName, Context.MODE_PRIVATE)?
假设我在私人文件夹中创建了一个文件,如下所示:
val dir = context.getDir("myDir", Context.MODE_PRIVATE)
val file = File(dir, "myFileName")
provider_path.xml的内容应该是什么?
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<!--for file created inside context.getFilesDir() directory-->
<files-path name="someDirectory" path="."/>
<!--for files created inside "myDir" ???-->
</paths>
我知道如何获取在 context.getFilesDir() 中创建的文件的 URI,但是否可以获取在另一个私有目录中创建的文件的 URI?
提前致谢!
What should be the content of provider_path.xml?
如果您指的是FileProvider
,它不支持任意位置,例如getDir("myDir", Context.MODE_PRIVATE)
。将您的文件存储在受支持的位置(例如 getFilesDir()
的子目录)或编写您自己的 ContentProvider
以提供自定义目录中的文件。
假设我在私人文件夹中创建了一个文件,如下所示:
val dir = context.getDir("myDir", Context.MODE_PRIVATE)
val file = File(dir, "myFileName")
provider_path.xml的内容应该是什么?
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<!--for file created inside context.getFilesDir() directory-->
<files-path name="someDirectory" path="."/>
<!--for files created inside "myDir" ???-->
</paths>
我知道如何获取在 context.getFilesDir() 中创建的文件的 URI,但是否可以获取在另一个私有目录中创建的文件的 URI?
提前致谢!
What should be the content of provider_path.xml?
如果您指的是FileProvider
,它不支持任意位置,例如getDir("myDir", Context.MODE_PRIVATE)
。将您的文件存储在受支持的位置(例如 getFilesDir()
的子目录)或编写您自己的 ContentProvider
以提供自定义目录中的文件。