2011-06-08 61 views
0

當瀏覽器中的地址叮噹響時,它將打開地址的地圖視圖。如何處理地圖: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; 
     } 
    } 
+0

我有同樣的問題,這個工作非常適合我... http://stackoverflow.com/questions/3583264/support-for-other-protocols-in-android-webview – droopie 2011-12-24 23:56:55

回答

0

我有同樣的問題。我拼湊一起通過看這個問題:

Question on geo:

的代碼添加到你的是下面......順便說一句,你幫我解決電話:問題!謝謝!

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

和回報true ..... – TrippinBilly 2011-08-16 16:54:02

+0

嗨我試着處理地理:我的web視圖中的鏈接,建議這裏。但是我得到一個錯誤:android.content.ActivityNotFoundException:找不到處理Intent的活動。這應該如何解決? – Zeba 2012-08-30 10:16:20