【发布时间】:2015-04-10 19:06:09
【问题描述】:
我想要的是将链接保留在 Web 视图中,只要它们是网站的一部分,但外部链接应该启动到外部 Web 浏览器中。同样在网站上,如果我使用电话号码下方的代码工作并启动电话应用程序但外部链接不起作用,我有电话链接与电话:555-323-2323。
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
if (url.contains("tel:")) {
startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(url)));
return true;
} else {
return true;
}
if (Uri.parse(url).getHost().equals("www.example.com")) {
// This is my web site, so do not override; let my WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
【问题讨论】: