質問

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