Open external links in the browser with android webview

后端 未结 4 1830
感情败类
感情败类 2020-11-30 01:30

I have this code, but not because it works, it keeps opening in webview and what I want is that the links do not belong to my website open in your default browser. Any idea?

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 01:36

    Here is very sweet and short solution

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        context.startActivity(i);
        return true;
    }
    

提交回复
热议问题