如何在webview中处理geo:链接

时间:2011-06-08 06:14:52

标签: android webview android-webview

当在浏览器中的地址上叮当作响时,它将打开地址的地图视图。

如何设置shouldOverrideUrlLoading以在WebView中处理这些链接?我已设置处理“tel:”和“mailto:”链接,但无法弄清楚如何处理“geo:”链接。

我的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;
        }
    }

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。我通过查看这个问题将它拼凑在一起:

Question on geo:

添加到你的代码是...... btw,你帮我解决了tel:问题! THX!

else if (url.startsWith("geo:")) {
        Intent searchAddress = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
        startActivity(searchAddress); 
}