birukhimself
birukhimself

Reputation: 193

How to check version of google play services in firebase app

My app uses Firebase auth and database. Whenever a phone with a lower Google Play Services version uses the app... the functionality doesn't work and it doesn't tell the user that the version is too low and that they should update, but it does log to the logcat. So my question is: Do I display the warning manually or is there a way firebase can do it for me? If I have to do it manually, how?

Upvotes: 3

Views: 3850

Answers (2)

Onur A.
Onur A.

Reputation: 3017

For manually checking Google Play Services version; you can use below;

int gpsVersion = getPackageManager().getPackageInfo(GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE, 0).versionCode;

Upvotes: 1

Martin De Simone
Martin De Simone

Reputation: 2148

During app initialization, your code should call GoogleApiAvailability.makeGooglePlayServicesAvailable(). Example use in onCreate() of main Activity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

GoogleApiAvailability.getInstance().makeGooglePlayServicesAvailable(this)
    .addOnCompleteListener(this, new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                Log.d(TAG, "onComplete: Play Services OKAY");
            } else {
                // Show the user some UI explaining that the needed version
                // of Play Services could not be installed and the app can't run.
            }
        }
});

...
}

Upvotes: 6

Related Questions