'isGooglePlayServicesAvailable'(this)已弃用

时间:2017-01-07 14:47:01

标签: java android android-studio

我正在关注tutuorial使用谷歌位置服务。所以,我正在尝试使用Google API服务获取位置。但是我得到isGooglePlayServicesAvailable(这个)已被弃用的错误。谁能帮忙。感谢

以下是检查设备上是否存在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;
}

1 个答案:

答案 0 :(得分:59)

使用isGooglePlayServicesAvailable代替

GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context)
相关问题