[翻译]GooglePlayServicesUtil Google服务工具类

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 常量
StringGOOGLE_PLAY_SERVICES_PACKAGEPackage name for Google Play services.    谷歌服务包名
intGOOGLE_PLAY_SERVICES_VERSION_CODEMinimum Google Play services package version (declared in AndroidManifest.xml android:versionCode) in order to be compatible with this client version.       最小版本号
StringGOOGLE_PLAY_STORE_PACKAGEPackage name for Google Play services.       谷歌商店包名

 

ConnectionResult 错误号对应

intDATE_INVALIDThe device date is likely set incorrectly.
intDEVELOPER_ERRORThe application is misconfigured.
intDRIVE_EXTERNAL_STORAGE_REQUIREDThe Drive API requires external storage (such as an SD card), but no external storage is mounted.
intINTERNAL_ERRORAn internal error occurred.
intINVALID_ACCOUNTThe client attempted to connect to the service with an invalid account name specified.
intLICENSE_CHECK_FAILEDThe application is not licensed to the user.
intNETWORK_ERRORA network error occurred.
intRESOLUTION_REQUIREDCompleting the connection requires some form of resolution.
intSERVICE_DISABLEDThe installed version of Google Play services has been disabled on this device.
intSERVICE_INVALIDThe version of the Google Play services installed on this device is not authentic.
intSERVICE_MISSINGGoogle Play services is missing on this device.
intSERVICE_VERSION_UPDATE_REQUIREDThe installed version of Google Play services is out of date.
intSIGN_IN_REQUIREDThe client attempted to connect to the service but the user is not signed in.
intSUCCESSThe connection was successful.

 

该工具类方法:

Public Methods
static DialoggetErrorDialog(int errorCode, Activity activity, int requestCode, DialogInterface.OnCancelListener cancelListener)
Returns a dialog to address the provided errorCode.
static DialoggetErrorDialog(int errorCode, Activity activity, int requestCode)
Returns a dialog to address the provided errorCode.
static PendingIntentgetErrorPendingIntent(int errorCode, Context context, int requestCode)
Returns a PendingIntent to address the provided errorCode.
static StringgetErrorString(int errorCode)
Returns a human-readable string of the error code returned from  isGooglePlayServicesAvailable(Context).
static StringgetOpenSourceSoftwareLicenseInfo(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 ContextgetRemoteContext(Context context)
This gets the Context object of the Buddy APK.
static ResourcesgetRemoteResource(Context context)
This gets the Resources object of the Buddy APK.
static intisGooglePlayServicesAvailable(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 booleanisUserRecoverableError(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)

判断这个错误号是否可以覆盖,如果可以就进行对话框提示

转载于:https://www.cnblogs.com/act262/p/3571654.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值