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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13766592/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 19:34:27  来源:igfitidea点击:

Android 8 or higher: Check for Google Play Services

javaandroideclipsegoogle-mapsgoogle-play

提问by Mark Molina

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. Does anybody know how to use this?

此方法保持返回 0。根据开发人员文档,如果设备获得最新版本的 google play,此方法应返回类似 SUCCES 的内容。有人知道如何使用这个吗?

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

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

回答by Raghav Sood

It is returning SUCCESS. The documentationclearly states that the method had an int return type, and returns a

它正在返回SUCCESS。该文档明确指出该方法具有 int 返回类型,并返回一个

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
}

回答by Rawkode

Please read the documentation: 0is SUCCESS

请阅读文档:0SUCCESS

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

Documentation

文档

回答by user219882

Simply

简单地

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

回答by Arun Kumar

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();
        }