1

For days...I try to find a solution to load a remote url with android webview. But with local css/js/images

But I couldn't.

I think it is impossible because of security issue... right?

I think mybe I could use a trick.

in remote server I just publish my webpage without <head> and <body>:

//<html>
    // <head></head>
    // <body>
        ... body  code111 ...  // there is only this part in remote url page
    //</body>
//</html>

and then I create a index.html in android_asset folder:

<html>
    <head>
        <link css ...
        <link java ...
    </head>
    <body>
        ... now put code111 here!
    </body>
</html>

So now I can use local resource (in head)

I am new in android and java...I couldn't test it...but do you think is it possible?

Vladimir Markeev
  • 654
  • 10
  • 25
partiz
  • 1,206
  • 2
  • 13
  • 34
  • You can load css from assets folder to web view. Have a look on this answer http://stackoverflow.com/a/7736654/1384010 – Adarsh Yadav Jul 23 '15 at 18:03

1 Answers1

0

well, let's start.

The easyer part is part B.

here you can find the answer: Rendering HTML in a WebView with custom CSS

basically, what you have to do is have the html website on a String variable, ex:

   String website = "<html><head>" + "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />" + <"javascript call to file that i don't remember right now"/>" + "</head>"

and then append to that website, your remote HTML code. you could do it via, for example, any of the Async HTTP libraries ( LoopJ's one is quite good loopj's http library ) .

and then append the rest of your website.

website += retrieved_website
website += "</body></html>"

finally load the website using the .loadDataWithBaseURL() method as explained in the accepted respose.

althought i have to say this is quite a complicated way of loading a website, this would be my approach.

Community
  • 1
  • 1
CptEric
  • 897
  • 9
  • 23
  • The good approach would be to create a websevice for both your website and a native app with a native UI. – Roel Jun 14 '17 at 15:41