Google Play services is an Android library whose goal is to provide:
Google Play服务是一个Android库,其目标是提供:
- OAuth 2.0 authentication
- Google+ sign-in
- Google+ +1 button
- various other goodies
OAuth 2.0身份验证
Google+ +1按钮
各种其他好吃的东西
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, etc)
如果我要使用它(例如,因为我希望Google+登录),那么设备没有Google Play的用户会怎样? (Nook,Cyanogenmod,中国移动,旧设备等)
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?
问题:我的应用会与这些设备不兼容吗?它会显示为兼容但随后崩溃,还是不起作用?在使用Google Play服务时,是否有最佳做法要记住这一点?
3 个解决方案
#1
23
If the feature from Google Play Services is essential for your app there would be no way to get your App working.
如果Google Play服务中的功能对您的应用至关重要,则无法让您的应用运行。
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.
您可以使用GooglePlayServicesUtil.isGooglePlayServicesAvailable(android.content.Context)检查是否已在您的应用中启用服务,如果Play服务可用,则返回ConnectionResult.SUCCESS。
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.
由于Google Play服务不是清单中声明的功能,因此您的应用应该可以在任何设备上正常安装,但如果您使用API而不检查它们是否可用,则可能会在以后崩溃。
You can try the behaviour with the emulator. Just create an AVD without the Google APIs and put your App on it.
您可以使用模拟器尝试该行为。只需在没有Google API的情况下创建AVD并将您的应用程序放在其上。
#2
23
GooglePlayServicesUtil.isGooglePlayServicesAvailable(android.content.Context)
is deprecated!
Use:
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();
}
#3
-2
If you are somehow required to use Play Services, or if you maintain a legacy app that makes calls to Play Services, then I would recommend this strategy:
如果您以某种方式需要使用Play服务,或者如果您维护一个传统应用程序来调用Play服务,那么我会推荐这个策略:
- On app start, check whether Play Services is available or not
- If not available, redirect Play Services calls to NOGAPP
在应用开始时,检查Play服务是否可用
如果不可用,请将Play服务重定向到NOGAPP
NOGAPP is an open source implementation of Google Play Services.
It lacks many features, but is under active development. Many features are still stubs.
NOGAPP是Google Play服务的开源实现。它缺乏许多功能,但正在积极开发中。许多功能仍然存根。
For location services, there is LOST, a drop-in replacement for the Google Play services location APIs.
对于位置服务,有一个LOST,它是Google Play服务位置API的直接替代品。
You app might not work perfectly, but at least it is better than crashing.
你的应用程序可能无法完美运行,但至少它比崩溃更好。
Of course, the best is to NOT use Google Play Services, from the start.
当然,最好的是从一开始就不要使用Google Play服务。
#1
23
If the feature from Google Play Services is essential for your app there would be no way to get your App working.
如果Google Play服务中的功能对您的应用至关重要,则无法让您的应用运行。
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.
您可以使用GooglePlayServicesUtil.isGooglePlayServicesAvailable(android.content.Context)检查是否已在您的应用中启用服务,如果Play服务可用,则返回ConnectionResult.SUCCESS。
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.
由于Google Play服务不是清单中声明的功能,因此您的应用应该可以在任何设备上正常安装,但如果您使用API而不检查它们是否可用,则可能会在以后崩溃。
You can try the behaviour with the emulator. Just create an AVD without the Google APIs and put your App on it.
您可以使用模拟器尝试该行为。只需在没有Google API的情况下创建AVD并将您的应用程序放在其上。
#2
23
GooglePlayServicesUtil.isGooglePlayServicesAvailable(android.content.Context)
is deprecated!
Use:
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();
}
#3
-2
If you are somehow required to use Play Services, or if you maintain a legacy app that makes calls to Play Services, then I would recommend this strategy:
如果您以某种方式需要使用Play服务,或者如果您维护一个传统应用程序来调用Play服务,那么我会推荐这个策略:
- On app start, check whether Play Services is available or not
- If not available, redirect Play Services calls to NOGAPP
在应用开始时,检查Play服务是否可用
如果不可用,请将Play服务重定向到NOGAPP
NOGAPP is an open source implementation of Google Play Services.
It lacks many features, but is under active development. Many features are still stubs.
NOGAPP是Google Play服务的开源实现。它缺乏许多功能,但正在积极开发中。许多功能仍然存根。
For location services, there is LOST, a drop-in replacement for the Google Play services location APIs.
对于位置服务,有一个LOST,它是Google Play服务位置API的直接替代品。
You app might not work perfectly, but at least it is better than crashing.
你的应用程序可能无法完美运行,但至少它比崩溃更好。
Of course, the best is to NOT use Google Play Services, from the start.
当然,最好的是从一开始就不要使用Google Play服务。