您的位置:首页 > 编程语言 > Go语言

检测设备是否支持Google Play服务

2017-01-11 08:59 513 查看
 一、使用GoogleAPiClient类访问Google Play服务功能(被建议使用)

二、使用方法isGooglePlayServicesAvailable()=====》仅仅只是判断手机是否安装了googleplay而已,但是是否可以使用google功能却无法判断(如三星S7可以安装googelplay,但是使用时就报错‘服务停止’),所以觉得不是很完美

使用GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(),不要使用过时的方法GooglePlayServicesUtil.isGooglePlayServicesAvailable()。

错误代码值和注意事项与方法一中一致。

PS:

出现Google Play服务不可用的错误时,可以使用GoogleApiAvailability.getInstance().getErrorDialog()弹出官方提供的对话框,这会根据不同的错误代码来给用户提供不同的操作,比如是进行升级操作还是下载操作。

思路:

  1.判断是否安装了Google play serive

  2.如果安装了,尝试连接使用google service,

int statusCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(mContext);
GoogleApiClient mGoogleApiClient2 = null;
//int statusCode = GooglePlayServicesUtil .isGooglePlayServicesAvailable(mContext);
if (statusCode == ConnectionResult.SUCCESS) {
mGoogleApiClient2= new GoogleApiClient.Builder(mContext)
.addApi(Fitness.HISTORY_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(@Nullable Bundle arg0) {
statusCallBack(isAvailableModuleContext, true, "GooglePlayServicesUtil service is available. onConnected");
}
@Override
public void onConnectionSuspended(int arg0) {
}

})
.addOnConnectionFailedListener(
new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult arg0) {
statusCallBack(isAvailableModuleContext, false, "GooglePlayServicesUtil service is NOT available. OnConnectionFailedListener");
}
}) .build();
if(mGoogleApiClient2!=null){
mGoogleApiClient2.connect();
}
} else {
if (GooglePlayServicesUtil.isUserRecoverableError(statusCode)) {
}
statusCallBack(moduleContext, false, "GooglePlayServicesUtil is null");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: