Reputation: 21
in my code the google api client returns the false value even it is being connected
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);
}
thanks in advance
Upvotes: 2
Views: 4944
Reputation: 199795
mGoogleApiClient.connect();
is not a synchronous operation - that's why you set up a addConnectionCallbacks(this)
when building your GoogleApiClient
.
You have to wait for the onConnected() callback before mGoogleApiClient.isConnected()
will return true
and you can use the GoogleApiClient
.
Upvotes: 9
Reputation:
use this method to return true for you.
public RequestAssync connect(){
SystemStatus ss = Android.request.connection();
if(ss.isConnect()){
return ss.getStatus();
}else{
return false;
}
}
Upvotes: 0