GoogleServices之GooglePlayService官方文档翻译

 GoogleServices之GooglePlayService官方文档翻译

在更广泛的设备上给你的应用程序更多的特性去吸引用户,使用GooglePlayService,你的应用程序能利用最新的优势,谷歌驱动特性比如地图,Googl+和更多,使用自动分布式更新平台通过GooglePlay商店更新APK.这使他更快的为你的用户接收更新和更容易的为你集成谷歌提供的最新的

GoogleTechnology(谷歌科技)
Googleplay services 为你提供轻松访问谷歌服务,与安卓系统紧密集成。每个服务提供了易于使用的客户端库,让你实现你想要的功能更容易、更快捷
StandardAuthorization (标准授权)
所有产品在googleplayservices共享一个公共授权API,利用现有的谷歌账户授权到设备上。你和你的用户有一个一致的和安全的方式给予和接收OAuth2谷歌服务访问令牌
AutomaticUpdates (自动更新)
设备运行安卓2.3或更高版本的googleplaystore,应用程序将自动接收更新谷歌服务。提高你的应用程序的最新版本的谷歌服务,而不用担心你的用户的Android版本

为了开始集成googleplayservice在你的应用中,请遵循以下安装指南:

为了使用googleplayservices APIS 开发应用,你需要在你的项目中设置googleplayservicesSDK。

如果你还没有安装googleplayservice SDK,去按照以下指南获取 Adding SDKPackages.

当你使用googleplayservice SDK测试你的应用时,必须使用以下:

1,一个兼容安卓并包含googleplaystore的设备,运行在2.3或更高版本。

2,安卓虚拟设备的模拟器需要运行googleAPIS 平台并且基于安卓4.2.2或更高。

 Add Google Play Services to Your Project

在你的项目中添加googleplayservices   使用工具:eclipse+ADT

使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开发了。

 

Create a Proguard Exception (创建一个异常混淆器)

为了防止混淆器从必要的类剥离,请在<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.

Ensure Devices Have the Google Play services APK

确保设备有GooglePlayService APK。

按照GooglePlayServices的介绍,googleplay为在2.3或更高版本的用户通过googlplaystore应用提供服务更新,然后,更新获取不能立即达到每个用户,所以你的应用在验证有效版本之前尝试实行API事务。

重点:因为很难预测每个设备的状态,你必须在你访问googleplayservice之前应该经常检查googlplayservice的兼容性。对于众多的应用,最佳的检测时间是在主activity的onResume方法中。

Google Playservices库包含的实用方法帮助你确定设备上的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_MISSINGSERVICE_VERSION_UPDATE_REQUIRED, or SERVICE_DISABLED,那么用户需要安装更新,所以,调用GooglePlayServicesUtil.getErrorDialog()不管他的错误码。他将会返回一个能展现的对话框,它提供了一个适当的消息和一个action让用户去Google PlayStore to安装更新。

下来开始连接到Google Play services(像GoogleDriver,Google+Games一样需要更多的Google APIS,阅读访问 Google APIS

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值