How to block any ads in webvew like adblock or adblock plus in browsers?

Viewed 5172

is there some library for android for block any ads? how to block using javascript injection?

When I code

webView1.getSettings().setJavaScriptEnabled(true);

the ads are shown, but other option of the page not working as the menu or filters. then how can I block ads but not disable javascript?

2 Answers

For reference, the AdBlock plus Github page offers an AdblockWebView. To use it, you add this line to your Gradle file:

implementation 'org.adblockplus:adblock-android-webview:3.14'

And then add this to your layout's XML file:

<org.adblockplus.libadblockplus.android.webview.AdblockWebView
    android:id="@+id/main_webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

It works just like a regular WebView component.

Related