Android google api客户端已连接返回false

Android google api客户端已连接返回false,android,google-api-client,Android,Google Api Client,在我的代码中,google api客户端返回假值,即使它正在连接 GoogleApiClient mGoogleApiClient; btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(TAG,"btn is clicked"); buildGoogleApiClient()

在我的代码中,google api客户端返回假值,即使它正在连接

GoogleApiClient mGoogleApiClient;
btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.i(TAG,"btn is clicked");
            buildGoogleApiClient();
            Log.i(TAG,"build google api completed");
            mGoogleApiClient.connect();
            if(mGoogleApiClient.isConnected())
            Log.i(TAG,"client conneted");
            Log.i(TAG,String.valueOf(mGoogleApiClient.isConnected()));


        }
});

protected synchronized void buildGoogleApiClient() {
    Log.i(TAG, "Building GoogleApiClient");
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();
    createLocationRequest();
}

protected void createLocationRequest() {
    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
    mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}

提前感谢

使用此方法为您返回true

public RequestAssync connect(){
    SystemStatus ss = Android.request.connection();
    if(ss.isConnect()){
        return ss.getStatus();
    }else{
        return false;
    }
}

mGoogleApiClient.connect()
不是同步操作-这就是为什么在构建
GoogleAppClient
时设置
addConnectionCallbacks(this)


您必须等待回调,然后
mgoogleapclient.isConnected()
将返回
true
,您可以使用
Googleapclient

为ConnectionCallbacks和ConnectionFailedListener添加代码吗?也许可以打印出他们的一些信息。嗨,快速提问。我已经设置了一个回调,以便在触发onConnected()时打印消息。之后,我设置了一个按钮来打印“mgoogleapclient.isConnected()”,但是即使在onConnected()回调成功之后,它仍然打印false。你知道为什么吗?