In a WebView is there a way for shouldOverrideUrlLoading to determine if it is catching a redirect vs. a user clicking a link?

前端 未结 6 574
时光说笑
时光说笑 2021-02-01 06:06

I would like to allow redirects to happen naturally in the WebView and only catch a new url if it is a happening because a user clicked something.

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-01 06:39

    I just found something in that SDK that might work, WebView.getHitTestResult() Let me know if anyone sees any flaws in this method.

    Here is an example of how I am using it:

    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if(view.getHitTestResult().getType() > 0){
             // From a user click, handle it yourself.
             return true;
        } else {
             // Nothing clicked, assumed to be a redirect, let it redirect.
             return false;
        }
    }
    

提交回复
热议问题