28

Google Play services is an Android library whose goal is to provide:

  • OAuth 2.0 authentication
  • Google+ sign-in
  • Google+ +1 button
  • various other goodies

If I were to use it (for instance because I want Google+ sign-in), what would happen to users whose device does not have Google Play? (Nook, Cyanogenmod, China Mobile, old devices, maybe Huawei?, etc)

QUESTION: Will my app become incompatible with such devices? Will it be displayed as compatible but then crash, or not work?
Is there a best practice to keep this in mind when using Google Play services?

4

4 回答 4

29
GooglePlayServicesUtil.isGooglePlayServicesAvailable(android.content.Context)

已弃用!

利用:

 GoogleApiAvailability api = GoogleApiAvailability.getInstance();
        int code = api.isGooglePlayServicesAvailable(activity);
        if (code == ConnectionResult.SUCCESS) {
           // Do Your Stuff Here
        } else {
           AlertDialog alertDialog =
                 new AlertDialog.Builder(activity, R.style.AppCompatAlertDialogStyle).setMessage(
                       "You need to download Google Play Services in order to use this part of the application")
                       .create();
           alertDialog.show();
        }
于 2016-01-22T09:53:40.557 回答
26

If the feature from Google Play Services is essential for your app there would be no way to get your App working.

You can check if the services are enabled from within your app with GooglePlayServicesUtil.isGooglePlayServicesAvailable(android.content.Context)
which returns ConnectionResult.SUCCESS if Play Services is available.

You can now try to convince the user to install it (if possible) or disable the feature that is using the service.

As the Google Play Services is not a feature declared in the manifest your app should install fine on any device but may crash later on if you are using the APIs without checking if they are available.

You can try the behaviour with the emulator. Just create an AVD without the Google APIs and put your App on it.

于 2012-11-02T09:37:19.790 回答
0

如果您的应用使用 Google 登录或 Firebase 云消息传递等 GMS 功能,那么它在没有 GMS 的设备上将无法正常运行。如果设备支持 GMS,建议您使用 GMS;否则,请使用 HMS(华为移动服务)。

请参考以下链接:

因此,您可以在支持 GMS 的设备上使用 Google+ 登录;否则,请使用华为帐号登录。

于 2020-05-15T07:40:27.920 回答
-2

如果您以某种方式需要使用 Play 服务,或者如果您维护一个调用 Play 服务的旧版应用程序,那么我建议您使用以下策略:

  1. 在应用启动时,检查 Play Services 是否可用
  2. 如果不可用,请将 Play 服务调用重定向到 microG

microG是 Google Play 服务的开源实现。
它缺乏许多功能,但正在积极开发中。许多功能仍然是存根。

对于位置服务,还有LOST,它是 Google Play 服务位置 API 的替代品。

您的应用程序可能无法完美运行,但至少比崩溃要好。

当然,最好的办法是从一开始就不要使用 Google Play 服务。

于 2014-05-21T07:05:05.147 回答