如何在Firebase应用中检查Google Play服务的版本

3

我的应用程序使用Firebase认证和数据库。每当低版本的Google Play服务的手机使用该应用程序时...功能无法正常工作,也不会告诉用户版本太低,需要更新,但它会记录到Logcat中。所以我的问题是:我是否要手动显示警告,还是Firebase可以为我完成?如果我必须手动完成,怎么做呢?


1
FCM 文档 中有详细描述。 - Bob Snyder
2个回答

6

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

示例:在主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.
            }
        }
});

...
}

这是正确的答案。原来,它在文档中。 - birukhimself

1

要手动检查Google Play服务的版本,您可以使用以下方法:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接