在特定设备上获取ActivityNotFoundException以打开Goog​​le地图

时间:2011-06-22 00:05:18

标签: android google-maps android-intent

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

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)

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

请不要说“你需要将其添加到清单中”。在这种情况下,请告诉我为什么有些(并非所有)设备毫无例外地工作。

提前致谢。

1 个答案:

答案 0 :(得分:3)

com.google.android.maps是一个不同的应用程序/包,因此在AndroidManifest中声明它不会提供您想要的内容。我相信Android安装没有安装Maps应用程序,因此无法接收被解雇的Intent。