【问题标题】:android maps v2 offer play serviceandroid maps v2 提供播放服务
【发布时间】:2013-03-09 20:57:15
【问题描述】:
我已经成功运行了 android maps API v2,但后来我尝试测试我是否没有 Google Play 服务,应用程序是否会提供安装它。
所以我卸载了 Google Play 服务,我的应用程序现在崩溃了。它没有像在示例应用程序中那样提供安装 Google Play 服务。在 LogCat 中,其打印 Google play services is missing 和 NullPointerException 之后。在示例应用程序中,我没有看到任何处理该问题的代码,我猜它包含在地图库中。我使用SupportMapFragment,但在示例应用程序中也使用了它。
如何让应用像示例应用一样提供安装播放服务?
【问题讨论】:
标签:
android
android-maps-v2
google-play-services
【解决方案1】:
您可以为此使用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 服务的对话框。