我已将 WebView 设置为检测电话、电子邮件和地址(在这种情况下会转到 Google 地图)。这就是我所拥有的:
URL = "file:///android_asset/dir/people.html";
webView = (WebView) findViewById(R.id.webViewDir);
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("tel:")) {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
startActivity(intent);
return true;
} else if (url.startsWith("mailto:")) {
url = url.substring(7);
String body = "Body of message.";
Intent mail = new Intent(Intent.ACTION_SEND);
mail.setType("application/octet-stream");
mail.putExtra(Intent.EXTRA_EMAIL, new String[] { url });
mail.putExtra(Intent.EXTRA_SUBJECT, "Subject");
mail.putExtra(Intent.EXTRA_TEXT, body);
startActivity(mail);
return true;
} else if (url.startsWith("map:")){
url = url.substring(4);
String map = "http://maps.google.com/maps?q=" + url;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(map));
startActivity(intent);
return true;
}
return false;
}
});
webView.loadUrl(URL);