我正在尝试在我的Android应用中使用Google Play服务。如Google文档所述,我们需要在使用Google 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时,出现错误消息:
GooglePlayServicesUtil
消失了(对于“次要”更新来说这似乎是一种不好的做法),但是我没有看到它GoogleApiAvailability
可以代替它。