Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force WebView to skip images?

Can someone advice me how to tune up Android WebView to skip images from remote server (without image placeholders)

like image 442
Fagoter Avatar asked Jul 28 '11 09:07

Fagoter


People also ask

How do you override a WebView?

If you want to override certain methods, you have to create a custom WebView class which extends WebView . Also, when you are inflating the WebView , make sure you are casting it to the correct type which is CustomWebView . CustomWebView webView = (CustomWebView) findViewById(R. id.

What can I use instead of WebView?

Alternatives to WebView If you want to send users to a mobile site, build a progressive web app (PWA). If you want to display third-party web content, send an intent to installed web browsers. If you want to avoid leaving your app to open the browser, or if you want to customize the browser's UI, use Custom Tabs.

How can I make my WebView faster on Android?

I read about how to increase performance of WebView by implementing Caching web resources like JS, CSS and image files. You can also static resources in your native application, and by intercepting the Resource requests you can override the default behaviour of WebView.


2 Answers

Try using :

webView.getSettings().setLoadsImagesAutomatically(false);
like image 153
ChristopheCVB Avatar answered Jan 02 '23 21:01

ChristopheCVB


webView.getSettings().setBlockNetworkImage(true);

and in webview onPageFinished

webView.loadUrl("javascript:(function(){ var imgs=document.getElementsByTagName('img');"+
                         "for(i=0;i<imgs.length;i++) { imgs[i].style.display='none'; } })()");
like image 33
rrrrong Avatar answered Jan 02 '23 19:01

rrrrong