Discovery Services Services Services and Services Services used in the application

What i have

I have an application that is highly dependent on Google Play services (for Firebase), so I need the user device to install Play Services. More importantly, the version of Play Services installed on the device must be equal to or higher than the Play Services that I use in my application.

What I want

I want to show a message (possibly a dialogue or a snack bar) on the Splash screen of my application if the user uses an old version of Service Services, which version targeting I use in my application.

As of now, the version of Play Services that I use in my application is 10.0.1. Obviously, this is the name of the version.

I know I can do it

int v = getPackageManager().getPackageInfo("com.google.android.gms", 0 ).versionName;

But I can’t compare the versions of the Play Services installed on the device and the Play Services that I use? Should I do this using versionCode instead of versionName? If so, how do I find out the version code of the Services of the Services that I use?

Or is there another (or better) way to do this?

+4
source share
2 answers

This is the method I use .. cheers

public static boolean checkPlayServices(Context context) {
    final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
    GoogleApiAvailability api = GoogleApiAvailability.getInstance();
    int resultCode = api.isGooglePlayServicesAvailable(context);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (api.isUserResolvableError(resultCode))
            api.getErrorDialog(((Activity) context), resultCode, PLAY_SERVICES_RESOLUTION_REQUEST).show();
        else {
            showToast(context, "This device is not supported.", true);
            ((Activity) context).finish();
        }
        return false;
    }
    return true;
}
+10
source

Usman's answer is good, in addition you can call GoogleApiAvailability.makeGooglePlayServicesAvailable () in case of unsuccessful resulting code. Like this:

int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
    GoogleApiAvailability.getInstance().makeGooglePlayServicesAvailable(this);
}

.. : https://developers.google.com/android/reference/com/google/android/gms/common/GoogleApiAvailability

0

Source: https://habr.com/ru/post/1668642/


All Articles