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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With