Launching Google Maps and Navigator from Android App

China☆狼群 提交于 2019-12-18 12:44:09

问题


I have an android application which allows the user to open up google maps or navigator to show a certain address. This functionality was working in the past, but now I get the following error and the app crashes:

ERROR/AndroidRuntime(2165): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=google.navigation:q=MCNAMARA+TERMINAL+ROMULUS+MI+48174 }

The two intents I'm using are-

1) For Map:

    String uri = "geo:0,0?q=MCNAMARA+TERMINAL+ROMULUS+MI+48174";        
    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
    startActivity(i); 

2) For Navigator:

    String uri = "google.navigation:q=MCNAMARA+TERMINAL+ROMULUS+MI+48174";
    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
    startActivity(i); 

回答1:


Your first Intent should be fine on many devices, as that is documented and supported.

Your second Intent is neither documented nor supported AFAIK, and so you should not be using it.

Also, bear in mind that not every Android device will have Google Maps or Navigation. Use PackageManager and queryIntentActivities() to determine if anything will respond to your Intent, then disable UI paths as needed to prevent users from encountering the exception.




回答2:


Intent for starting Navigator:

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);

More details can be found here.



来源:https://stackoverflow.com/questions/3517484/launching-google-maps-and-navigator-from-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!