http://developer.android.com/reference/com/google/android/gms/common/GooglePlayServicesUtil.html
java.lang.Object | |
↳ | com.google.android.gms.common.GooglePlayServicesUtil |
这个工具类是用来检查设备是否安装以及最新的Google Play Service的,和执行PlusClient或者GoogleAuthUtil连接服务一样.
Constants 常量 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | GOOGLE_PLAY_SERVICES_PACKAGE | Package name for Google Play services. 谷歌服务包名 | |||||||||
int | GOOGLE_PLAY_SERVICES_VERSION_CODE | Minimum Google Play services package version (declared in AndroidManifest.xml android:versionCode) in order to be compatible with this client version. 最小版本号 | |||||||||
String | GOOGLE_PLAY_STORE_PACKAGE | Package name for Google Play services. 谷歌商店包名 |
ConnectionResult 错误号对应
int | DATE_INVALID | The device date is likely set incorrectly. |
int | DEVELOPER_ERROR | The application is misconfigured. |
int | DRIVE_EXTERNAL_STORAGE_REQUIRED | The Drive API requires external storage (such as an SD card), but no external storage is mounted. |
int | INTERNAL_ERROR | An internal error occurred. |
int | INVALID_ACCOUNT | The client attempted to connect to the service with an invalid account name specified. |
int | LICENSE_CHECK_FAILED | The application is not licensed to the user. |
int | NETWORK_ERROR | A network error occurred. |
int | RESOLUTION_REQUIRED | Completing the connection requires some form of resolution. |
int | SERVICE_DISABLED | The installed version of Google Play services has been disabled on this device. |
int | SERVICE_INVALID | The version of the Google Play services installed on this device is not authentic. |
int | SERVICE_MISSING | Google Play services is missing on this device. |
int | SERVICE_VERSION_UPDATE_REQUIRED | The installed version of Google Play services is out of date. |
int | SIGN_IN_REQUIRED | The client attempted to connect to the service but the user is not signed in. |
int | SUCCESS | The connection was successful. |
该工具类方法:
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
static Dialog | getErrorDialog(int errorCode, Activity activity, int requestCode, DialogInterface.OnCancelListener cancelListener)
Returns a dialog to address the provided errorCode.
|
||||||||||
static Dialog | getErrorDialog(int errorCode, Activity activity, int requestCode)
Returns a dialog to address the provided errorCode.
|
||||||||||
static PendingIntent | getErrorPendingIntent(int errorCode, Context context, int requestCode)
Returns a PendingIntent to address the provided errorCode.
|
||||||||||
static String | getErrorString(int errorCode)
Returns a human-readable string of the error code returned from
isGooglePlayServicesAvailable(Context) . |
||||||||||
static String | getOpenSourceSoftwareLicenseInfo(Context context)
Returns the open source software license information for the Google Play services application, or null if Google Play services is not available on this device.
|
||||||||||
static Context | getRemoteContext(Context context)
This gets the Context object of the Buddy APK.
|
||||||||||
static Resources | getRemoteResource(Context context)
This gets the Resources object of the Buddy APK.
|
||||||||||
static int | isGooglePlayServicesAvailable(Context context)
Verifies that Google Play services is installed and enabled on this device, and that the version installed on this device is no older than the one required by this client.
|
||||||||||
static boolean | isUserRecoverableError(int errorCode)
Determines whether an error is user-recoverable.
|
public static int isGooglePlayServicesAvailable (Context context)
根据上下文来检测谷歌服务是否安装并且正常可用,且安装的版本号不低于该应用的版本
根据检测到的不同情况返回下面的值(类型 ConnectionResult)
:
SUCCESS, SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, SERVICE_DISABLED, SERVICE_INVALID, DATE_INVALID.
public static Dialog getErrorDialog (int errorCode, Activity activity, int requestCode, DialogInterface.OnCancelListener cancelListener)
errorCode : 根据错误号,获取错误对话框,如果 isGooglePlayServicesAvailable(Context)
==SUCCESS 则返回null
activity :需要在哪里显示该对话框的对象
cancelListener : 对话框的监听器,当点击取消时添加指定动作(更新服务?退出?)
public static Dialog getErrorDialog (int errorCode, Activity activity, int requestCode) 同上
public static PendingIntent getErrorPendingIntent (int errorCode, Context context, int requestCode)
根据错误号,上下文等获取 PendingIntent
public static String getErrorString (int errorCode)
根据错误号来获取错误号所对应的字符值
public static String getOpenSourceSoftwareLicenseInfo (Context context)
获取谷歌服务软件版权声明信息
public static Context getRemoteContext (Context context)
获取远程操作的上下文对象
public static Resources getRemoteResource (Context context)
public static boolean isUserRecoverableError (int errorCode)
判断这个错误号是否可以覆盖,如果可以就进行对话框提示