Question

The basic idea is to alter every url being loaded in a webview (for example adding/removing get parameters).

I have a custom WebViewClient, in which I have the following method :

public boolean shouldOverrideUrlLoading(WebView view, String url) {
    String modifiedUrl = Util.someMethod(url);
    super.shouldOverrideUrlLoading(view, modifiedUrl);
}

Will it work or should I put this logic in another method, for example onPagestarted ?

Was it helpful?

Solution

You rather should do something like :

public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if(conditionForModifyingUrl){
        String modifiedUrl = Util.someMethod(url);
        view.loadUrl(modifiedUrl);
        return true;
    }
    return false;
}

Calling super.shouldOverrideUrlLoading(view, modifiedUrl) won't work because, as it is its name, this method only checks if the url should be overridden, and does not load the url at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top