你可以使用这个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 服务的对话框。