I have following activity which uses GoogleApiClient:
public class MainActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener
{
private final String TAG = "My App";
private TextView textView;
private GoogleApiClient mGoogleApiClient;
private LocationRequest mLocationRequest;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.v(TAG,"After layout setting");
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
textView = (TextView) findViewById(R.id.location);
Log.v(TAG,"After mGoogleClient");
}
@Override
protected void onStart() {
Log.v(TAG,"On Start");
super.onStart();
mGoogleApiClient.connect();
}
@Override
protected void onStop() {
Log.v(TAG,"On Stop");
mGoogleApiClient.disconnect();
super.onStop();
}
@Override
public void onConnected(Bundle bundle) {
Log.v(TAG,"on Connected");
mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setInterval(1000);
Log.v(TAG,"After Setting mLocationRequest");
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
Log.v(TAG,"Checking block");
return;
}
Log.v(TAG,"After Checking block");
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
Log.v(TAG,"After Request Location Updates");
}
@Override
public void onConnectionSuspended(int i) {
Log.v(TAG,"Suspended");
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Log.v(TAG,connectionResult.toString());
}
@Override
public void onLocationChanged(Location location) {
Log.v(TAG,location.toString());
textView.setText(location.toString());
}
}
After running this piece of code I get a message in logcat stating:
ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
Which is due to execution of OnConnectionFailed function ..
How to resolve this problem?