在Android模拟设备上升级Google Play服务

时间:2016-07-03 23:44:14

标签: android android-emulator google-play-services

我正在使用android studio开发应用程序,我使用模拟的Android设备来测试它。模拟设备是带有Android 4.4的Nexus 4(带有谷歌api)。

在我的项目中,我使用最新的播放服务客户端版本9.2.0:

enter image description here

当我在模拟器上启动我的应用程序时,会显示以下消息:

enter image description here

问题是:如何在模拟器上升级播放服务? TNX

1 个答案:

答案 0 :(得分:0)

只需将Google Play服务添加到您的项目中即可。要使Google Play Services API's适用于您的应用,请在dependencies下为play-services的最新版本添加新的构建规则。

打开应用程序模块目录中的build.gradle文件。

apply plugin: 'com.android.application'
...

dependencies {
compile 'com.google.android.gms:play-services:9.2.0'
}

每次更新Google Play服务时,请务必更新此版本号。

Google Play services overview所述,Google Play通过Google Play商店应用为Android 2.3及更高版本的用户提供服务更新。但是,更新可能无法立即覆盖所有用户,因此您的应用应在尝试执行API事务之前验证可用的版本。

由于每个应用都以不同方式使用Google Play服务,因此您可以自行决定应用中的相应位置以验证Google Play服务版本。例如,如果您的应用始终需要Google Play服务,则可能需要在应用首次启动时执行此操作。另一方面,如果Google Play服务是您应用的可选部分,则只有在用户导航到您应用的该部分后,您才能检查该版本。

强烈建议您使用GoogleApiClient课程来访问Google Play服务功能。此方法允许您将OnConnectionFailedListener对象附加到客户端。要检测设备是否具有相应版本的Google Play服务APK,请实施onConnectionFailed()回调方法。如果由于Google Play APK的丢失或过期版本导致连接失败,则回调会收到错误代码,例如SERVICE_MISSING