I want to have my webview refer to a site, say example.com. In the assets directory for the app, I will include all the static assets such as javascript, styles and the images.
However, when I use the following code on my website: <link rel="stylesheet" href="file:///android_asset/css/main.css">
But that just gives me an error.
Any ideas on how to do it?
This won't work directly, due to JavaScript's same-origin policy:
https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy
A possible workaround would be to process the remote site HTML as a String, and then load the HTML string using
loadDataWithBaseURL()
with theandroid-asset
base URL: