GoogleServices之GooglePlayService官方文档翻译html
在更普遍的设备上给你的应用程序更多的特性去吸引用户,使用GooglePlayService,你的应用程序能利用最新的优点,谷歌驱动特性好比地图,Googl+和更多,使用自动分布式更新平台经过GooglePlay商店更新APK. 这使他更快的为你的用户接收更新和更容易的为你集成谷歌提供的最新的。java
为了开始集成googleplayservice在你的应用中,请遵循如下安装指南:android
为了使用googleplayservices APIS 开发应用,你须要在你的项目中设置googleplayservices SDK。api
若是你尚未安装googleplayservice SDK,去按照如下指南获取 Adding SDK Packages.安全
当你使用googleplayservice SDK测试你的应用时,必须使用如下:app
1,一个兼容安卓并包含googleplaystore的设备,运行在2.3或更高版本。eclipse
2,安卓虚拟设备的模拟器须要运行google APIS 平台而且基于安卓4.2.2或更高。分布式
在你的项目中添加googleplayservices 使用工具:eclipse+ADTide
使googleplayservice可用于您的应用中:工具
1,在<android-sdk>/extras/google/google_play_services/libproject/google-play-services_lib/这个路径下复制库项目到你本地维护的安卓应用项目。
2,导入库项目在你的eclipse工做空间,Click File > Import, select Android > Existing Android Code into Workspace,浏览你拷贝的库项目并导入他。
3,在你的项目中,参考googleplayservices库项目,请看:Referencing a Library Project for Eclipse获取更多如何使用的信息。
注意:你应该参考你复制到你开发工做空间的库,而不是直接参考AndroidSDK目录中的。
4,接下来你应该为你的应用添加googleplayservice库的倚赖关系,打开你应用的manifest文件并按照下面标签添加到<application>节点中:
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
一旦你设置你的项目参考库项目,有就能够使用googleplayservice开发了。
为了防止混淆器从必要的类剥离,请在<project_directory>/proguard-project.txt
文件中添加一下行:
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
@com.google.android.gms.common.annotation.KeepName *;
}
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
注意:当你使用的是AndroidStudio,你必须添加混淆器在你的build,gradle中,获取更多信息,请看:Gradle Plugin User Guide.
确保设备有GooglePlayService APK。
按照GooglePlayServices的介绍,googleplay为在2.3或更高版本的用户经过googlplaystore应用提供服务更新,而后,更新获取不能当即达到每一个用户,因此你的应用在验证有效版本以前尝试实行API事务。
重点:由于很难预测每一个设备的状态,你必须在你访问googleplayservice以前应该常常检查googlplayservice的兼容性。对于众多的应用,最佳的检测时间是在主activity的onResume方法中。
Google Play services库包含的实用方法帮助你肯定设备上的Google Play services的版本是否支持你所使用的客户端库版本。若是设备上的版本太老,系统将让用户更新到最新的Google Play services版本。
因为每一个应用使用的Google Play services不尽相同,由你决定在你应用的适当位置来验证Google Play services的版本。好比:若是Google Play services在你的应用中时刻须要,你可能想在应用第一次加载的时候去作。另外一方面,若是Google Play services是你应用中可选的一部分,你只须要仅仅在你的应用的用户导航时去验证版本。
为了验证Google Play services版本,调用isGooglePlayServicesAvailable()
。若是结果码是 SUCCESS
, 那么 Google Play services APK是最新的,你能够继续链接。而后,结果码是SERVICE_MISSING
, SERVICE_VERSION_UPDATE_REQUIRED
, or SERVICE_DISABLED
,那么用户须要安装更新,因此,调用GooglePlayServicesUtil.getErrorDialog()
无论他的错误码。他将会返回一个能展示的对话框,它提供了一个适当的消息和一个action让用户去Google Play Store to安装更新。
下来开始链接到Google Play services(像GoogleDriver,Google+和Games同样须要更多的Google APIS),阅读访问 Google APIS