我的应用使用Firebase身份验证和数据库。每当具有较低Google Play服务版本的手机使用该应用程序时......该功能不起作用,并且它不会告诉用户该版本太低而且应该更新,但它会记录到logcat。所以我的问题是:我是否手动显示警告或者firebase是否可以为我执行此操作?如果我必须手动完成,怎么做?
答案 0 :(得分:5)
在应用初始化期间,您的代码应调用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.
}
}
});
...
}
答案 1 :(得分:1)
手动检查Google Play服务版本;你可以在下面使用;
int gpsVersion = getPackageManager().getPackageInfo(GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE, 0).versionCode;