问题描述
我有一个Android应用程序,它允许用户打开谷歌地图或导航显示某个地址。此功能是工作在过去,但现在我碰到下面的错误和应用程序崩溃:
ERROR / AndroidRuntime(2165):android.content.ActivityNotFoundException:无活动处理意向{行为= android.intent.action.VIEW DAT = google.navigation:Q = MCNAMARA +终端+ ROMULUS + MI + 48174}
这两个意图我使用的是 -
1)图:
字符串的uri =?缘:0,0 Q = MCNAMARA +终端+ ROMULUS + MI + 48174;
意图I =新的意图(Intent.ACTION_VIEW,Uri.parse(URI));
startActivity(ⅰ);
2)导航器:
字符串的uri =google.navigation:Q = MCNAMARA +终端+ ROMULUS + MI + 48174;
意图I =新的意图(Intent.ACTION_VIEW,Uri.parse(URI));
startActivity(ⅰ);
你的第一个意图
应罚款在许多设备上,因为这是的。
你的第二个目的是既不记录也不支持AFAIK,所以你不应该使用它。
另外,要记住,不是每一个Android设备将有谷歌地图或导航。使用 PackageManager
和 queryIntentActivities()
来确定什么将你的意图作出回应
,然后根据需要以prevent用户遇到异常关闭UI路径。
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);
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.
这篇关于启动谷歌地图和导航的Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!