gpt4 book ai didi

android - 缺少服务时,isGooglePlayServicesAvailable() 返回 ConnectionResult.SUCCESS

转载 作者:行者123 更新时间:2023-11-29 01:04:52 27 4
gpt4 key购买 nike

我已经实现了检查播放服务是否照常可用的代码:

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 应用程序在许多设备上崩溃。

附言我可以在 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 服务”确实可用并且是最新的。被禁用的应用程序是“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) {}

我希望这对某人有所帮助,非常感谢您的关注和愉快的编码。

附言如果您认为此解决方案不够优雅,请发表评论。

关于android - 缺少服务时,isGooglePlayServicesAvailable() 返回 ConnectionResult.SUCCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47995227/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com