blade
blade

Reputation: 853

How to get the URI of a file stored in a folder created with context.getDir(directoryName, Context.MODE_PRIVATE)?

Let's say I create a file inside the private folder like this:

val dir = context.getDir("myDir", Context.MODE_PRIVATE)
val file = File(dir, "myFileName")

What should be the content of 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>

I know how to get the URI for a file created inside context.getFilesDir(), but it is possible to get the URI of a file created inside another private directory?

Thanks in advance!

Upvotes: 1

Views: 803

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007474

What should be the content of provider_path.xml?

If you are referring to FileProvider, it does not support arbitrary locations, such as getDir("myDir", Context.MODE_PRIVATE). Either store your files in a supported location (e.g., a subdirectory off of getFilesDir()) or write your own ContentProvider to serve up the files from your custom directory.

Upvotes: 1

Related Questions