如何处理地理:在网页视图链接 [英] How to handle geo: links in webview
问题描述
在浏览器中的一个地址无比,它会打开地址的地图视图。
如何设置shouldOverrideUrlLoading处理中的WebView这些链接?我有设定处理电话:和mailto:链接,但无法弄清楚如何处理地缘。链接
我shouldOverrideUrlLoading:
公共布尔shouldOverrideUrlLoading(的WebView视图,字符串URL){
如果(url.startsWith(电话:)){
startActivity(新意图(Intent.ACTION_DIAL,Uri.parse(URL)));
返回true;
}否则如果(url.startsWith(电子邮件地址:)){
URL = url.replaceFirst(至mailto:,);
URL = url.trim();
意图I =新意图(Intent.ACTION_SEND);
i.setType(纯/文)putExtra(Intent.EXTRA_EMAIL,新的String [] {URL})。
startActivity(ⅰ);
返回true;
}否则如果(url.startsWith(地理)){
返回true;
}其他{
view.loadUrl(URL);
返回true;
}
}
我有同样的问题。我拼凑通过看这个问题一起:
<一个href=\"http://stackoverflow.com/questions/2372557/how-to-call-the-google-map-from-my-android-application-like-invoke-the-email\">Question关于地球:
在code以添加到您低于...顺便说一句,你帮我解决了电话:问题! THX!
如果别人(url.startsWith(地理)){
意图searchAddress =新意图(Intent.ACTION_VIEW,Uri.parse(URL));
startActivity(searchAddress);
}
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)));
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:
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);
}
这篇关于如何处理地理:在网页视图链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!