5

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?

anas darai
  • 71
  • 2
  • 6
angel
  • 4,474
  • 12
  • 57
  • 89

2 Answers2

2

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.

Akash Amin
  • 2,741
  • 19
  • 38
Code on the Rocks
  • 11,488
  • 3
  • 53
  • 61
1

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

anas darai
  • 71
  • 2
  • 6