开发者

Cache in a webview

开发者 https://www.devze.com 2023-03-20 16:28 出处:网络
Im trying the class WebView and have a few questions =) maybe you can help me I have noticed that if you charge an single image in the webview, the webview resizes it to the screens width,but with mul

Im trying the class WebView and have a few questions =) maybe you can help me I have noticed that if you charge an single image in the webview, the webview resizes it to the screens width,but with multitouch you can make it smaller. Is there any way of ignoring when the user attempts to make it smaller? Can I know when the page finished the load? and finally how can I 开发者_StackOverflow中文版save a full webpage for showing it to the user in offline mode?

Thanks so much in advance :D


Is there any way of ignoring when the user attempts to make it smaller?

Have a look at WebSettings.setSupportZoom()

Can I know when the page finished the load?

Configure a custom WebChromeClient as progress listener like this:

webview.setWebChromeClient(new WebChromeClient() {
    @Override
    public void onProgressChanged(WebView view, int progress)
    {
        if (progress == 100)
        {
                // do something
        }
    }
});

how can I save a full webpage for showing it to the user in offline mode?

Well, I'd like to know that as well, but I don't think its possible. For now I'm setting an aggressive cache mode (WebSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK)) and if my URL could not be loaded from cache, I load a locally available one from the resources:

final String urlToLoad = "http://www.my-url.com"; 
webview.setWebViewClient(new WebViewClient() {
    @Override
    public void onReceivedError(WebView view, int errorCode,
            String description, String failingUrl)
    {
        if (urlToLoad.equals(failingUrl))
        {
            view.loadUrl("file:///android_res/raw/local_copy.html");
            return;
        }
        super.onReceivedError(view, errorCode, description, failingUrl);
    }
});
webview.loadUrl(urlToLoad);
0

精彩评论

暂无评论...
验证码 换一张
取 消