How to link to a file stored in internal storage from WebView?

I have some files stored in the internal storage application, which is located here:

/ data / data // files /

Here's the problem: I want to link to these files from webview. How can I do it? What should be used as baseUrl?

I need something like the file: /// android_asset, but for the "internal storage" instead of the files in the resource directory.

+4
source share
2 answers

Try the following:

file:///data/data/com.yourproject.example/files/image.png 
+6
source

You should use Context.getFilesDir () when creating the path, and not hardcode the path to the application files. This ensures that the application will work even if your package / namespace changes.

Example:

 String filesPath = getFilesDir().getAbsolutePath(); String filePath = "file://" + filesPath + "/image.png"; 
+5
source

Source: https://habr.com/ru/post/1335302/


All Articles