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

Mar*_*ina 9 java eclipse android google-maps google-play

此方法继续返回0.根据开发人员文档,如果设备获得最新版本的google play,此方法应返回类似SUCCES的内容.有谁知道如何使用它?

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

        GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
        System.out.println("henkie: " + GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()));
    }
Run Code Online (Sandbox Code Playgroud)

Rag*_*ood 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
}
Run Code Online (Sandbox Code Playgroud)


Raw*_*ode 7

请阅读文档:0SUCCESS

public static final int SUCCESS
The connection was successful.
Constant Value: 0 (0x00000000)
Run Code Online (Sandbox Code Playgroud)

文档