9

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

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

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

4 回答 4

40

它正在回归SUCCESS文档清楚地指出该方法有一个 int 返回类型,并返回一个

指示是否有错误的状态码。ConnectionResult 中可以是以下之一:SUCCESS、SERVICE_MISSING、SERVICE_VERSION_UPDATE_REQUIRED、SERVICE_DISABLED、SERVICE_INVALID。

要检查返回的内容,请使用以下内容:

int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if(status == ConnectionResult.SUCCESS) {
    //Success! Do what you want
}
于 2012-12-07T16:03:56.463 回答
7

请阅读文档:0SUCCESS

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

文档

于 2012-12-07T16:02:36.490 回答
4

简单地

int statusCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if (statusCode == ConnectionResult.SUCCESS) {
    //OK
}
于 2012-12-07T16:05:58.407 回答
3
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();
        }
于 2014-10-31T13:39:35.900 回答