从 Android 应用程序启动 Google 地图和导航器
我有一个 Android 应用程序,它允许用户打开谷歌地图或导航器来显示某个地址。此功能过去可以正常工作,但现在出现以下错误并且应用程序崩溃:
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 }
我使用的两个意图是 -
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);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的第一个
Intent
在许多设备上应该没问题,因为它是 记录并支持。您的第二个意图既没有记录也不支持 AFAIK,因此您不应该使用它。
另外,请记住,并非所有 Android 设备都有 Google 地图或导航。使用
PackageManager
和queryIntentActivities()
确定是否有任何内容响应您的Intent
,然后根据需要禁用 UI 路径以防止用户遇到异常。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
andqueryIntentActivities()
to determine if anything will respond to yourIntent
, then disable UI paths as needed to prevent users from encountering the exception.启动 Navigator 的意图:
如需了解更多详情,请访问此处。
Intent for starting Navigator:
More details can be found here.