Skip to content

CodeBit25/WebViewAdblock

Repository files navigation

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.MonsterTechnoGits:WebViewAdblock:1.1'
   }

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

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages