如何确保您的Google Play服务APK已更新

每当Google更新其Play服务APK时,更新您的应用也很重要。请继续阅读以了解此快速流程。

如何确保您的Google Play服务APK已更新

如果您的应用使用任何Google API,则需要确保您的设备已更新Google Play服务APK。

首先,您必须确定需要插入代码以更新Google Play服务的准确位置。

如果您的应用完全基于Google Play服务,那么您可以在最初启动应用时执行此操作。但是,如果只有部分应用使用Google Play服务,则只要用户需要访问应用的该部分,就应该执行此操作。

现在有两种方法可以检查Google Play服务的可用性:

  1. 使用GooglePlayServicesUtil

int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

if(status != ConnectionResult.SUCCESS)

{

if(status == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED)

{

Toast.makeText(context,"Please udpate your google play services",Toast.LENGTH_SHORT).show();

}

}

但是这种方法的问题是GooglePlayServicesUtil的某些方法和字段已被弃用。

所以,第二个更好的方法(Google也推荐)是:

2.使用GoogleApiAvailability

GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();

int result = googleAPI.isGooglePlayServicesAvailable(activity);

if(result != ConnectionResult.SUCCESS)

{

if (googleAPI.isUserResolvableError(result))

{

googleAPI.getErrorDialog(activity, result, AppConstant.PLAY_SERVICES_RESOLUTION_REQUEST).show();

}

}

这将显示一个对话框,其中包含有关所发生错误的相应消息以及将您带到Play商店以安装或更新Google Play服务所需的操作。

最后,您的设备将使Google Play服务保持最新状态!


分享到:


相關文章: