marcelbohland / Android-Webview-Adblock

A Adblock System for Android Webview
https://github.com/marcelbohland/Android-Webview-Adblock-Example
Apache License 2.0
50 stars 11 forks source link

ad comes back when the webpage url is changed #3

Closed willjones911 closed 2 years ago

willjones911 commented 2 years ago

hey thanks for the help with ur code and other tutorials from codebit25 on youtube i kinda made the webview app work but the ad comes back when a change in url is detected then causing redirect and by pressing return it exits the app but after searching online i've come across a post https://stackoverflow.com/questions/9312499/android-detect-webview-url-change/56395424#56395424

where it mentions override fun doUpdateVisitedHistory(view: WebView?, url: String?, isReload: Boolean) { // your code here super.doUpdateVisitedHistory(view, url, isReload) }

by adding the above code it can fix this issue can u help me on where do i add the above code?

my MainActivity.java is as below, i'm assuming there's where i add it, your help will be highly appreciated i'm a newbie to this

package com.example.ngefilm21;

import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle; import android.webkit.WebResourceResponse; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient;

import java.util.HashMap; import java.util.Map;

public class MainActivity extends AppCompatActivity {

private WebView webview;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    AdBlocker.init(this);

    webview=(WebView)findViewById(R.id.webview);
    webview.setWebViewClient(new MyBrowser());

    WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(true);

    webview.loadUrl("https://www.ngefilm21.asia/"); //type your url
}

private class MyBrowser extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }

    private Map<String, Boolean> loadedUrls = new HashMap<>();
    @Nullable
    @Override

    public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
        boolean ad;
        if (!loadedUrls.containsKey(url)) {
            ad = AdBlocker.isAd(url);
            loadedUrls.put(url, ad);
        } else {
            ad = loadedUrls.get(url);
        }
        return ad ? AdBlocker.createEmptyResource() :
                super.shouldInterceptRequest(view, url);
    }
}

}

8mpty commented 2 years ago

@willjones911 have you gotten it to work yet cause I too have trouble with the ad blocking but with youtube video ads? btw

override fun doUpdateVisitedHistory(view: WebView?, url: String?, isReload: Boolean) 
{
       // your code here
       super.doUpdateVisitedHistory(view, url, isReload)
}

for Java should be this (below) the top code is for Kotlin if i'm not wrong?

public void doUpdateVisitedHistory(WebView view, String url, boolean isReload)
{
       // your code here
       super.doUpdateVisitedHistory(view, url, isReload);
}

If you have found a solution, please do let me know how you overcome it. Thanks

willjones911 commented 2 years ago

Sorry couldn't get it to work given up on the project as the website I was using had too many ads on it for like certain article site for YouTube you can use YouTube vance,revance,Vue tube,or YouTube vanced extended, (smart tube next) for Android tv otherwise the app I was tryna make it works but the moment redirect ads come in and I hit back it exits the app ended up given up it's Easier to use ublock origin extension on Firefox nightly mobile or Firefox regular on Android or at android tv, Nvidia shield etc tv box

On Thu, Jun 16, 2022, 2:46 AM 25-Khairin @.***> wrote:

@willjones911 https://github.com/willjones911 have you gotten it to work yet cause I too have trouble with the ad blocking but with youtube video ads? btw

override fun doUpdateVisitedHistory(view: WebView?, url: String?, isReload: Boolean) { // your code here super.doUpdateVisitedHistory(view, url, isReload) }

for Java should be this (below) the top code is for Kotlin if i'm not wrong?

public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) { // your code here super.doUpdateVisitedHistory(view, url, isReload); }

If you have found a solution, please do let me know how you overcome it. Thanks

— Reply to this email directly, view it on GitHub https://github.com/marcelbohland/Android-Webview-Adblock/issues/3#issuecomment-1156809980, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR73CMTLS5IGJRZS4WKVYE3VPIQIXANCNFSM5U2KCKHA . You are receiving this because you were mentioned.Message ID: @.***>