I’m using a WebView in my Android app to load up our Web App, eg…
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_web_view = (WebView) findViewById(R.id.web);
_web_view.loadUrl(R.strings.url);
}
So far, so good.
What I want to do is selectively choose to load available assets out of the local Android filesystem when the WebView requests them. The idea is that I will save significant load time and bandwidth by packaging static image assets into the Android and serving them from the filesystem, rather than requesting them from the web server.
I see that the WebViewClient class has a onLoadResource method. This is very close to what I want, except I would like to have a way to tell the app “no, don’t download it from THAT url, use THIS url instead” (and point to the local filesystem).
The best approach I can think of thus far is to simply have a different copy of our .html file that points to the Android filesystem, but I would prefer to selectively replace the assets on the clientside rather than maintaining 2 copies of the HTML on the server…
Thanks!
Take a look at overriding
shouldInterceptRequestinstead. It seems to be what you want. The downside being requiring API 11+.