open ads in external browser in webview android

前端 未结 2 1404
太阳男子
太阳男子 2020-12-20 02:10

I created app with webview, and i want load all internal links in webview and load external links in android browser. Now problem is I am using html ads and when i click on

2条回答
  •  长情又很酷
    2020-12-20 02:59

    You code should be:

    @Override   
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (Uri.parse(url).getHost().equals("www.mysite.com")) {
            return true;
        }else{
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);
            return false;
        }
    }
    

    All I changed was:

    1.) Returning true loads the URL in the webview, no need for view.loadUrl()

    2.) Return false when you broadcast the ACTION_VIEW intent

提交回复
热议问题