【问题标题】:How to check version of google play services in firebase app如何在 Firebase 应用程序中检查 Google Play 服务的版本
【发布时间】:2018-08-19 04:09:03
【问题描述】:

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

【问题讨论】:

标签: android firebase firebase-realtime-database firebase-authentication google-play-services


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    在应用初始化期间,您的代码应调用 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.
                }
            }
    });
    
    ...
    }
    

    【讨论】:

    • 这是正确答案。原来,它在文档上。
    猜你喜欢
    • 2013-09-15
    • 1970-01-01
    • 2016-09-29
    • 2018-12-22
    • 1970-01-01
    • 2012-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多