WebView does not load assets correctly

I have a WebView that I use to display some html / image files stored in the assets/ directory. I can have a WebView and html page load with:

 mWebView.loadUrl("file:///android_asset/ContentRoot/SubDir/file.html"); 

or

 String data = StaticFunctions.inputStreamToString(getAssets().open("ContentRoot/SubDir/file.html")); mWebView.loadDataWithBaseURL("file:///android_asset/ContentRoot/SubDir/file.html", data, "text/html", "UTF-8", null); 

The problem I am facing is that there are images in HTML like:

 <img src="../Photos/image.jpg" alt="whatever" /> 

and instead of loading from assets/ContentRoot/Photos/image.jpg he tries to load them from assets/Photos/image.jpg .

Why is he trying to download them from the wrong (relative) location and what can I do to fix the problem?

+6
android webview assets
source share
1 answer

Oh man ... I missed something stupid here. The html was simply erroneous, and the Photos directory was not upstream from the source. Sorry for the confusion.

0
source share

All Articles