我需要检查手机是否已启用/禁用/可用/未安装播放服务。
我使用以下代码
final int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (status != ConnectionResult.SUCCESS) {
Log.e(TAG, GooglePlayServicesUtil.getErrorString(status));
return false;
} else {
Log.i(TAG, GooglePlayServicesUtil.getErrorString(status));
return true;
}
即使播放服务是禁用状态也返回为“2”。怎么过来这个。?
答案 0 :(得分:1)
我正在使用onActivityResult来处理这种情况。
public void callMarketPlace() {
try {
//if play services are disabled so it will return request code 1 and result code 0 in OnActivity result.
startActivityForResult(new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id="+ "com.google.android.gms")), 1);
}
catch (android.content.ActivityNotFoundException anfe) {
startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 1);
}
}
关于活动结果
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
boolean isEnable = false;
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
if (resultCode == 0) {
if (isEnable){
isEnable = false;
} else {
Intent intent = new Intent(); intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", "com.google.android.gms", null); intent.setData(uri);
startActivityForResult(intent,1);
isEnable = true;
}
}
}
}
答案 1 :(得分:0)
对于那些试图弄清楚如何启用google play服务的人来说,只需注意,上述方法
GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
现已弃用。请改用GoogleApiAvailability的实例
GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(getActivity());