gregm
gregm

Reputation: 12149

How do I reference a file stored in internal storage from a WebView?

I have some files stored in the app's "internal storage", which is located on the device here:

/data/data//files/

Here's the problem: I want to reference these files from the webview. How do I do this? What should I use as the baseUrl?

I need something similar to file:///android_asset but for "internal storage" instead of for files in the assets directory.

Upvotes: 5

Views: 4937

Answers (2)

disco
disco

Reputation: 1506

You should use Context.getFilesDir() when generating the path, not hard coding the application's files-path. This will ensure that the application will still work even if your package/namespace changes.

Example:

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

Upvotes: 5

Gilbou
Gilbou

Reputation: 5254

Try this:

file:///data/data/com.yourproject.example/files/image.png

Upvotes: 9

Related Questions