[英]Launching Google Maps and Navigator from Android App
我有一個android應用程序,允許用戶打開google maps或navigator以顯示特定地址。 過去曾使用過此功能,但現在出現以下錯誤,應用程序崩潰:
ERROR / AndroidRuntime(2165):android.content.ActivityNotFoundException:找不到用於處理Intent的活動{act = android.intent.action.VIEW dat = google.navigation:q = MCNAMARA + TERMINAL + ROMULUS + MI + 48174}
我使用的兩個意圖是-
1)對於地圖:
String uri = "geo:0,0?q=MCNAMARA+TERMINAL+ROMULUS+MI+48174";
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);
2)對於導航器:
String uri = "google.navigation:q=MCNAMARA+TERMINAL+ROMULUS+MI+48174";
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);
您的第一個Intent
在許多設備上都應該很好,因為已記錄並受支持 。
您的第二個Intent既沒有記錄也沒有受支持的AFAIK,因此您不應使用它。
另外,請記住,並非每台Android設備都會有Google Maps或Navigation。 使用PackageManager
和queryIntentActivities()
確定是否有任何響應您的Intent
,然后根據需要禁用UI路徑,以防止用戶遇到異常。
啟動導航器的意圖:
Intent navigation = new Intent(Intent.ACTION_VIEW, Uri.parse(“http://
maps.google.com/maps?
saddr=42.35892,-71.05781&daddr=40.756054,-73.986951”));
startActivity(navigation);
可以在此處找到更多詳細信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.