简体   繁体   English

如何在firebase应用中查看google play服务的版本

[英]How to check version of google play services in firebase app

My app uses Firebase auth and database. 我的应用使用Firebase身份验证和数据库。 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. 每当具有较低Google Play服务版本的手机使用该应用程序时......该功能不起作用,并且它不会告诉用户该版本太低而且应该更新,但它会记录到logcat。 So my question is: Do I display the warning manually or is there a way firebase can do it for me? 所以我的问题是:我是否手动显示警告或者firebase是否可以为我执行此操作? If I have to do it manually, how? 如果我必须手动完成,怎么做?

During app initialization, your code should call GoogleApiAvailability.makeGooglePlayServicesAvailable(). 在应用初始化期间,您的代码应调用GoogleApiAvailability.makeGooglePlayServicesAvailable()。 Example use in onCreate() of main Activity: 在主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.
            }
        }
});

...
}

For manually checking Google Play Services version; 用于手动检查Google Play服务版本; you can use below; 你可以在下面使用;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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