如何将 Google Play 服务更新到 9.8.7 for 运行 on Google Pixel

How to update Google Play Services to 9.8.7 for running on Google Pixel

我正在按照 https://developers.google.com/android/guides/setup, setting the Google Play Services at 9.8.0 in my build.gradle file. As described in 的说明尝试实施我的应用程序,为了在模拟器上进行测试,我应该降级该服务。但是,它也表明它应该可以在物理设备上运行。

I/FirebaseInitProvider: FirebaseApp initialization unsuccessful

W/GooglePlayServicesUtil: Google Play services out of date. Requires 9877000 but found 9384448

E/MainActivity: Connection to Google API client has failed

我已经更新了 SDK Manager/Tools(版本 37)中的 Google Play 服务,但我 运行 没有想法。我不确定如何在 Pixel 上降级 Google Play 服务。我是否遗漏了什么(可能很明显?)

EDTI:查看答案,我在 phone 上缺少 Google Play 服务的正确版本。该解决方案实施检查以防止将来出错。

您应该添加一些代码来检查是否需要更新。像下面这样。

GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
    googlePlayServicesAvailable = googleApiAvailability.isGooglePlayServicesAvailable((Variables.context));
        if ((googlePlayServicesAvailable == ConnectionResult.SERVICE_MISSING) || (googlePlayServicesAvailable == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED) || (googlePlayServicesAvailable == ConnectionResult.SERVICE_DISABLED)) {
                            activity.this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + context.getPackageName())));
                            googleApiAvailability.getErrorDialog(((Activity) Variables.context), googlePlayServicesAvailable, 0);
        }

您应该将我的代码修改为:

  1. 询问用户是否希望升级
  2. 如果未安装 Play 商店 ActivityNotFoundException