1
votes

I am loading a html file stored inside internal memory of android. I use below line to load the html url.

webView.loadUrl("file:///" + file);  

Here file location will be like /data/data/apppackagename/localcontent/html/../../../home.html

My issue is that html file loads fine in webview. However it is not referring css and js files in other folders.

For example: if html file resides in below location.

/data/data/apppackagename/localcontent/html/../../../home.html

And js and css resides in same location like

/data/data/apppackagename/localcontent/html/../../../xyz.css
/data/data/apppackagename/localcontent/html/../../../abc.js

then it works fine by referring js and css files

But if html file resides in below location.

/data/data/apppackagename/localcontent/html/../../../home.html

And js and css resides in same location like

/data/data/apppackagename/localcontent/html/../../../css/xyz.css
/data/data/apppackagename/localcontent/html/../../../js/abc.js

then it is not referring css and js files while loading in webview.

Plz note that i am downloading the html files from web and storing internal memory and accessing it in when no network.

Also paths inside html files are relative only. Please someone help me on this. Thanks in advance.

Last Edit:

I have analyzed and found that some css/js files are not downloading properly and that's why html was not loading properly. I checked the files in rooted device. thanks.

1
I recommend to add html files, css and js in assets folder. - Balu SKT

1 Answers

0
votes

In html file refer css and js like shown below, if the html file , js and css are in same folder.

<script src="js/src.js"></script>
<link href="css/css.css" type="text/css" rel="stylesheet" />

This worked for me.