Firebase:如何确保与各种版本的Google Play服务兼容? [英] Firebase: How can I ensure compatibility with various versions of Google Play Services?

查看:239
本文介绍了Firebase:如何确保与各种版本的Google Play服务兼容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Android应用程序中合并消息传递/推送通知,并且由于FCM是推荐的最新版本,所以我只检查了Firebase的先决条件,并说,

I want to incorporate messaging/Push notifications in my Android App and since FCM is the newest version recommended, I just checked the Firebase prerequisites and it says,

先决条件

  • 运行Android 4.0(Ice Cream Sandwich)或更高版本以及Google Play服务10.2.0或更高版本的设备

  • A device running Android 4.0 (Ice Cream Sandwich) or newer, and Google Play services 10.2.0 or higher

Google存储库中的Google Play服务SDK,可在Android SDK管理器中找到

The Google Play services SDK from the Google Repository, available in the Android SDK Manager

最新版本的Android Studio 1.5或更高版本

The latest version of Android Studio, version 1.5 or higher

但是,并不是所有运行ICS的设备都具有> = 10.2.0的Google Play服务.实际上,这是它的最新版本.因此,如果我决定使用FCM,则所有具有Play Services< = 10.2.0的设备都将无法使用.如果那样的话,我决定降低版本,Firebase似乎不支持任何版本.

But, it isn't so that all the devices running ICS will have Google Play Services >= 10.2.0. Infact, this is the latest version of it. So, if I decide to go with FCM, all the devices having Play Services <= 10.2.0 will be out of my reach. If then I decide to bump the version down, Firebase doesn't seem to support any.

我想使用Firebase和Google Play服务的最新功能,并扩展对运行Google Play服务> = 9.0.0的设备的支持.

I want to use Firebase's and Google Play Services newest features and extend my support for devices running Google Play services >= 9.0.0.

这似乎是任何库的基本问题. Android提供了支持库来减轻这种情况.

This seems to be a fundamental problem with any library. Android provides Support library to mitigate this.

支持所有这些Play服务版本的推荐方法是什么?

What is the recommended approach to support all these Play Services versions?

推荐答案

只需通过放置 checkers ,使用户更新到最新的Google Play服务.从文档:

Just have the user update to the latest Google Play Services, by placing checkers. From the docs:

依赖Play服务SDK的应用在访问Google Play服务功能之前,应始终检查设备是否有兼容的Google Play服务APK.建议在两个位置执行此操作:在主活动的onCreate()方法中,以及在其onResume()方法中. onCreate()中的检查可确保在未成功检查的情况下无法使用该应用程序. onResume()中的检查可确保如果用户通过其他方式(例如通过后退"按钮)返回到正在运行的应用,则仍会执行检查.

Apps that rely on the Play Services SDK should always check the device for a compatible Google Play services APK before accessing Google Play services features. It is recommended to do this in two places: in the main activity's onCreate() method, and in its onResume() method. The check in onCreate() ensures that the app can't be used without a successful check. The check in onResume() ensures that if the user returns to the running app through some other means, such as through the back button, the check is still performed.

如果设备没有兼容版本的Google Play服务,则您的应用可以调用

If the device doesn't have a compatible version of Google Play services, your app can call GoogleApiAvailability.makeGooglePlayServicesAvailable() to allow users to download Google Play services from the Play Store.

这篇关于Firebase:如何确保与各种版本的Google Play服务兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆