How to handle geo: links in webview
When clinking on an address in the browser, it will open a map view for the address.
How do I set shouldOverrideUrlLoading to handle these links in a WebView? I have setup handling of "tel:" and "mailto:" links, but can't figure out how to handle "geo:" links.
My shouldOverrideUrlLoading:
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("tel:")) {
startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(url)));
开发者_JAVA技巧 return true;
} else if (url.startsWith("mailto:")) {
url = url.replaceFirst("mailto:", "");
url = url.trim();
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("plain/text").putExtra(Intent.EXTRA_EMAIL, new String[]{url});
startActivity(i);
return true;
} else if (url.startsWith("geo:")) {
return true;
} else {
view.loadUrl(url);
return true;
}
}
I was having the same problem. I pieced it together by looking at this question:
Question on geo:
the code to add to yours is below... btw, you helped me solve the tel: issue! thx!
else if (url.startsWith("geo:")) {
Intent searchAddress = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(searchAddress);
}
精彩评论