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 ?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top