简体   繁体   中英

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?

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

...
}

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM