【问题标题】:Getting ActivityNotFoundException on specific device to open Google Maps在特定设备上获取 ActivityNotFoundException 以打开 Google 地图
【发布时间】:2011-06-22 00:05:18
【问题描述】:

在我的应用中,我使用以下代码打开 Google 地图。

String map_url = "geo:0,0?q=";
map_url += String.valueOf((double)latitude / 1E6) + ",";
map_url += String.valueOf((double)longitude / 1E6);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
intent.setData(Uri.parse(map_url));
startActivity(intent);

它在许多设备上都运行良好。但是今天我看到了 ACRA 的暗恋报告。

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.google.android.apps.maps/com.google.android.maps.MapsActivity}; have you declared this activity in your AndroidManifest.xml?
    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
    at android.app.Activity.startActivityForResult(Activity.java:2817)
    at android.app.Activity.startActivity(Activity.java:2923)

设备是运行 OS2.2.2 的 Vortex。异常清楚地告诉我我需要在清单中声明“com.google.android.maps.MapsActivity”。问题是,我没有这样做,但它适用于许多设备,所以结果不一致:为什么我在该设备上得到异常而我没有在许多其他设备上得到异常?

请不要说“您需要将其添加到清单中。”在这种情况下,请告诉我为什么某些(不是所有)设备都能正常工作。

提前致谢。

【问题讨论】:

  • 您的 map_url 字符串无意中解决了我在尝试让内置地图应用程序在启动时为请求提供服务时遇到的一个持续问题。 "geo:0,0?q=" 是关键,谢谢!!

标签: android google-maps android-intent


【解决方案1】:

com.google.android.maps 是一个不同的应用程序/包,所以在你的 AndroidManifest 中声明它不会给你想要的东西。我相信 Android 安装没有安装 Maps 应用程序,因此无法接收触发的 Intent。

【讨论】:

  • 就像 Abhinav 所说,在你的 AndroidManifest 中声明它不会做任何事情。您只需在 AndroidManifest 中声明您自己的活动。我建议用 try/catch 包围它,并显示一条消息,告诉用户他/她需要从市场上下载谷歌地图,并为用户提供一个链接,将他/她带到那里。
  • 感谢您的回答,感谢@magicman clearing 建议我应该做什么。我会按照你的建议去做。
猜你喜欢
  • 1970-01-01
  • 2014-04-11
  • 1970-01-01
  • 2021-11-16
  • 1970-01-01
  • 1970-01-01
  • 2021-11-20
  • 2012-01-14
  • 2013-01-16
相关资源
最近更新 更多