isGooglePlayServicesAvailable() returns ConnectionResult.SUCCESS 当服务缺失时
isGooglePlayServicesAvailable() returns ConnectionResult.SUCCESS when service is missing
我已经实现了检查播放服务是否照常可用的代码:
mGooglePlayServicesAvailable = false;
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
if (resultCode == ConnectionResult.SUCCESS) {
mGooglePlayServicesAvailable = true;
}
else if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(this, resultCode, RC_AVAILABILITY).show();
}
我的问题是 resultCode 似乎是 ConnectionResult.SUCCESS 即使缺少服务。这会使我的 android 应用程序在许多设备上崩溃。
P.S。我可以在 logcat 中看到以下行,这很奇怪。
E/GooglePlayServicesUtil(12419): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
关于可能导致此行为的原因的任何想法,或者是否有更好的方法来检查播放服务是否可用?
非常感谢,干杯!
经过一些研究,我发现 ConnectionResult.SUCCESS 背后的原因是 'Google Play Services' 确实可用并且是最新的。被禁用的应用程序是 'Google Play Games',所以我只需要稍微扩展我的代码以更好地处理这种情况:
mGooglePlayGamesAvailable = false;
try {
int status = getPackageManager().getApplicationEnabledSetting("com.google.android.play.games");
switch(status) {
case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
// check if play services are up to date
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
if (resultCode == ConnectionResult.SUCCESS) {
mGooglePlayGamesAvailable = true;
}
else if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(this, resultCode, RC_AVAILABILITY).show();
}
break;
}
} catch(IllegalArgumentException e) {}
我希望这对某人有所帮助,非常感谢您的关注和愉快的编码。
P.S。如果觉得这个方案不够优雅,欢迎评论。
我已经实现了检查播放服务是否照常可用的代码:
mGooglePlayServicesAvailable = false;
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
if (resultCode == ConnectionResult.SUCCESS) {
mGooglePlayServicesAvailable = true;
}
else if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(this, resultCode, RC_AVAILABILITY).show();
}
我的问题是 resultCode 似乎是 ConnectionResult.SUCCESS 即使缺少服务。这会使我的 android 应用程序在许多设备上崩溃。
P.S。我可以在 logcat 中看到以下行,这很奇怪。
E/GooglePlayServicesUtil(12419): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
关于可能导致此行为的原因的任何想法,或者是否有更好的方法来检查播放服务是否可用?
非常感谢,干杯!
经过一些研究,我发现 ConnectionResult.SUCCESS 背后的原因是 'Google Play Services' 确实可用并且是最新的。被禁用的应用程序是 'Google Play Games',所以我只需要稍微扩展我的代码以更好地处理这种情况:
mGooglePlayGamesAvailable = false;
try {
int status = getPackageManager().getApplicationEnabledSetting("com.google.android.play.games");
switch(status) {
case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
// check if play services are up to date
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
if (resultCode == ConnectionResult.SUCCESS) {
mGooglePlayGamesAvailable = true;
}
else if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(this, resultCode, RC_AVAILABILITY).show();
}
break;
}
} catch(IllegalArgumentException e) {}
我希望这对某人有所帮助,非常感谢您的关注和愉快的编码。
P.S。如果觉得这个方案不够优雅,欢迎评论。