Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 732
angel Avatar asked Oct 18 '22 09:10

angel


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.

like image 187
Joe Muller Avatar answered Oct 21 '22 04:10

Joe Muller


You can use this official library:
https://github.com/adblockplus/libadblockplus-android

like image 37
anas darai Avatar answered Oct 21 '22 04:10

anas darai