1

我已经成功运行了 android maps API v2,但后来我尝试测试我是否没有 Google Play 服务,应用程序是否会提供安装它。

所以我卸载了 Google Play 服务,我的应用程序现在崩溃了。它没有像在示例应用程序中那样提供安装 Google Play 服务。在 LogCat 它的打印Google play services is missing和之后NullPointerException。在示例应用程序中,我没有看到任何处理该问题的代码,我猜它包含在地图库中。我正在使用SupportMapFragment,但是在示例应用程序中也使用了它。

如何使应用程序提供安装播放服务,如其在示例应用程序中?

4

1 回答 1

5

你可以使用这个GooglePlayServicesUtil类。您的代码将如下所示:

int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
if (resultCode == ConnectionResult.SUCCESS) 
{
    // Google Play Services installed correctly, continue
} 
else if (resultCode == ConnectionResult.SERVICE_MISSING ||
         resultCode == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED ||
         resultCode == ConnectionResult.SERVICE_DISABLED) 
{           
    // Google Play Services not installed / too old / disabled.
    // Show dialog to install or update
    Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this, 1);
    dialog.show();
} 
else 
{
    // Something else went wrong, handle this yourself
}

getErrorDialog方法将显示将用户定向到 Google Play 商店以安装或更新 Google Play 服务的对话框。

于 2013-03-09T21:42:30.123 回答