简体   繁体   English

Android 8或更高版本:检查Google Play服务

[英]Android 8 or higher: Check for Google Play Services

this method keep returning 0. According to the developer docs this method should return something like SUCCES if the device got the newest version of google play. 此方法继续返回0.根据开发人员文档,如果设备获得最新版本的google play,此方法应返回类似SUCCES的内容。 Does anybody know how to use this? 有谁知道如何使用它?

@Override
    public void onResume() {
        super.onResume();

        GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
        System.out.println("henkie: " + GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()));
    }

It is returning SUCCESS . 它正在返回SUCCESS The documentation clearly states that the method had an int return type, and returns a 文档清楚地说明该方法具有int返回类型,并返回a

status code indicating whether there was an error. 状态代码,指示是否有错误。 Can be one of following in ConnectionResult: SUCCESS, SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, SERVICE_DISABLED, SERVICE_INVALID. 可以是ConnectionResult中的以下之一:SUCCESS,SERVICE_MISSING,SERVICE_VERSION_UPDATE_REQUIRED,SERVICE_DISABLED,SERVICE_INVALID。

To check against what was returned, use something like: 要检查返回的内容,请使用以下内容:

int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if(status == ConnectionResult.SUCCESS) {
    //Success! Do what you want
}

Please read the documentation: 0 is SUCCESS 请阅读文档: 0SUCCESS

public static final int SUCCESS
The connection was successful.
Constant Value: 0 (0x00000000)

Documentation 文档

Simply 只是

int statusCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if (statusCode == ConnectionResult.SUCCESS) {
    //OK
}
int state = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

        if (state == ConnectionResult.SUCCESS) {
            Toast.makeText(this, "SUCCESS", Toast.LENGTH_LONG).show();
            //goAhead();
        } else {
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(state, this, -1);
            dialog.show();
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM