AppsCDN / WebViewAdblock-Updated-Blocklist

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WebViewAdblock

Android webview Adblocker is a simple library to block ads in webview. this code is basicaly stop the ads and remove the html from it and render it again.

Image of Webview Adblock

How do I use it?

Step 1

#1 Add it in your root build.gradle at the end of repositories:

	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

Step 2

Add the dependency in app level build.gradle file

	dependencies {
           implementation 'com.github.AppsCDN:WebViewAdblock-Updated-Blocklist:1.5'
   }

Step 3

Inisialize the webview in your activity where you have the webview.

new AdBlockerWebView.init(this).initializeWebView(webView);

Step 4

Now to block ads we need to add this code in the WebViewClient so extentd the WebViewClient for your webview like this and then in the class overide this method.

webView.setWebViewClient(new Browser_home());
private class Browser_home extends WebViewClient {

        Browser_home() {}

        @SuppressWarnings("deprecation")
        @Override
        public WebResourceResponse shouldInterceptRequest(WebView view, String url) {

            return AdBlockerWebView.blockAds(view,url) ? AdBlocker.createEmptyResource() :
                    super.shouldInterceptRequest(view, url);

        }

    }

Now you can run your app to see if the ads are blocked. You can always use other webview features and add fetures to the webview.

About


Languages

Language:Java 100.0%