gpt4 book ai didi

android - google api客户端已连接返回false

转载 作者:太空狗 更新时间:2023-10-29 15:52:34 26 4
gpt4 key购买 nike

在我的代码中,即使正在连接,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);
}

提前致谢

最佳答案

mGoogleApiClient.connect(); 不是同步操作 - 这就是您在构建 GoogleApiClient 时设置 addConnectionCallbacks(this) 的原因.

您必须等待 onConnected() mGoogleApiClient.isConnected() 之前的回调将返回 true,您可以使用 GoogleApiClient

关于android - google api客户端已连接返回false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28348345/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com