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?

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

The good approach would be to create a websevice for both your website and a native app with a native UI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.