检测设备是否支持Google Play服务
2017-01-11 08:59
615 查看
一、使用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");
}
二、使用方法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");
}
相关文章推荐
- 检测设备是否支持Google Play服务
- 检测设备是否支持Google Play服务
- 检测设备是否支持多任务
- 检测安卓手机设备是否支持USB Host诊断工具
- 检测设备是否支持触屏
- 用SecurAble检测cpu是否支持Intel VT虚拟化技术的LOCKED ON,LOCKED OFF,YES,NO使用说明
- iOS中检测是否支持多任务
- 检测浏览器是否支持webp格式
- 检测是浏览器还是手机,需求为是否支持FLASH,此文为检测是否支持FLASH的代码(含demo下载)
- 检测.a文件是否支持64位
- 使用python检测一个设备是否ping的通
- cookie的作用和检测用户浏览器是否支持cookie
- 【小技巧】HTML中检测浏览器是否受支持
- 检测浏览器是否支持hmtl5视频的方法
- 检测浏览器是否支持WMP(Windows Media Player)
- 安卓罗盘开发检测系统是否支持电子多盘
- Android检测设备是否连上网络
- cmake检测g++编译器是否支持c++11
- 检测是浏览器还是手机,需求为是否支持FLASH,此文为检测是否支持FLASH的代码(含demo下载)
- linux设备上的Onvif 实现9:检查是否支持该设备