Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 452
gregm Avatar asked Jan 12 '11 20:01

gregm


2 Answers

Try this:

file:///data/data/com.yourproject.example/files/image.png
like image 95
Gilbou Avatar answered Sep 28 '22 09:09

Gilbou


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";
like image 34
disco Avatar answered Sep 28 '22 07:09

disco