Dave Dave - 1 year ago 187
Android Question

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

I am trying to implement my app, following the instructions from https://developers.google.com/android/guides/setup, setting the Google Play Services at 9.8.0 in my build.gradle file. As described in How to update Google Play Services to 9.8.7, for testing on an emulator I should downgrade the service. However, it also indicates it should work on a physical device.

  • I am using the new Google Pixel phone which has Google Play Services 9.3.84 installed, Android 7.1.

  • The build.gradle file includes:
    compile 'com.google.android.gms:play-services:9.8.0'

  • Once running the adb debugger shows

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

I've updated the Google Play Services in the SDK Manager/Tools (version 37), but am running out of ideas. I am unsure how to downgrade the Google Play Services on the Pixel. Am I missing something (possibly obvious?)

Answer Source

You should add some code to check if there is an update required. Like this below.

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);

You should modify my code to:

  1. Ask the user if they wish to upgrade
  2. Catch if the play store is not installed with a ActivityNotFoundException
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download