gpt4 book ai didi

android - GooglePlayServicesUtil 与 GoogleApiAvailability

转载 作者:IT老高 更新时间:2023-10-28 13:04:58 28 4
gpt4 key购买 nike

我正在尝试在我的 Android 应用中使用 Google Play 服务。正如谷歌文档所说,我们需要在使用之前检查谷歌 API 是否可用。我已经搜索了一些方法来检查它。这是我得到的:

private boolean checkPlayServices() {
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this,
PLAY_SERVICES_RESOLUTION_REQUEST).show();
} else {
Log.i(TAG, "This device is not supported.");
finish();
}
return false;
}
return true;
}

但是当我转到 Google Api GooglePlayServicesUtil 页面时, https://developers.google.com/android/reference/com/google/android/gms/common/GooglePlayServicesUtil

我发现所有功能都已弃用。比如方法

GooglePlayServicesUtil.isGooglePlayServicesAvailable(已弃用)

Google 建议使用:

GoogleApiAvailability.isGooglePlayServicesAvailable

但是,当我尝试使用 GoogleApiAvailability.isGooglePlayServicesAvailable 时,我收到错误消息:

enter image description here

最佳答案

我找到了解决方案。在 GoogleApiAvailability 中,所有方法都是公共(public)方法,而在 GooglePlayServicesUtil 中,所有方法都是静态公共(public)函数。

所以要使用GoogleApiAvailability,正确的方法是:

private boolean checkPlayServices() {
GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
int result = googleAPI.isGooglePlayServicesAvailable(this);
if(result != ConnectionResult.SUCCESS) {
if(googleAPI.isUserResolvableError(result)) {
googleAPI.getErrorDialog(this, result,
PLAY_SERVICES_RESOLUTION_REQUEST).show();
}

return false;
}

return true;
}

关于android - GooglePlayServicesUtil 与 GoogleApiAvailability,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31016722/

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