如何在 firebase 应用程序中检查 google 播放服务的版本

How to check version of google play services in firebase app

我的应用程序使用 Firebase 身份验证和数据库。每当具有较低 Google Play 服务版本的 phone 使用该应用程序时......该功能不起作用并且它不会告诉用户版本太低并且他们应该更新,但它确实记录到 logcat。所以我的问题是:我是手动显示警告还是 firebase 可以为我做这件事?如果我必须手动执行,该怎么做?

在应用程序初始化期间,您的代码应调用 GoogleApiAvailability.makeGooglePlayServicesAvailable()。 在 main Activity:

的 onCreate() 中使用示例
@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.
            }
        }
});

...
}

用于手动检查 Google Play 服务版本;您可以在下面使用;

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