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

问题描述

|| 在我的应用中,使用以下代码打开Goog​​le Maps。
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 \”。问题是,我没有执行此操作,但它可用于许多设备,因此结果不一致:为什么我在该设备上遇到异常而我在其他设备上却没有得到? 请不要说“您需要将其添加到清单中。”在这种情况下,请告诉我为什么某些(并非全部)设备无例外地工作。 提前致谢。     

解决方法

        
com.google.android.maps
是不同的应用程序/程序包,因此在AndroidManifest中声明它不会满足您的要求。我相信Android安装中未安装Maps应用程序,因此无法收到触发的Intent。