Android 我正在尝试在不使用不推荐的方法的情况下检查google play服务。有什么见解吗?

Android 我正在尝试在不使用不推荐的方法的情况下检查google play服务。有什么见解吗?,android,location,google-play-services,deprecated,Android,Location,Google Play Services,Deprecated,我一直在构建一个需要位置感知的应用程序,并且刚刚通过谷歌play服务获得了位置感知。问题是,我能在网上找到的唯一检查服务是否可用的方法是不推荐的。我真的需要一些投入,这是现在应该做的 以下是不推荐使用的版本: private boolean checkPlayServices() { int resultCode = GooglePlayServicesUtil .isGooglePlayServicesAvailable(this); if (res

我一直在构建一个需要位置感知的应用程序,并且刚刚通过谷歌play服务获得了位置感知。问题是,我能在网上找到的唯一检查服务是否可用的方法是不推荐的。我真的需要一些投入,这是现在应该做的

以下是不推荐使用的版本:

  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 {
            Toast.makeText(getApplicationContext(),
                    "This device is not supported.", Toast.LENGTH_LONG)
                    .show();
            finish();
        }
        return false;
    }
    return true;
}
注:私有最终静态整数播放服务解析请求=1000

注:私有最终静态整数播放服务解析请求=1000

-这是解决方案-这是解决方案
/** Method to verify google play services on the device */
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();
        } else {
            Log.i(TAG, "This device is not supported.");
            finish();
        }
        return false;
    }
    return true;
}