0

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?

Rocket
  • 1,030
  • 5
  • 24

2 Answers2

0

You need to update your Google Play Services. Are you running your code in emulator? If so, try again with higher API level. This code works fine in real device.

Sudip Podder
  • 830
  • 11
  • 25
  • Go for a real device. I tried your code, worked without any problem :) – Sudip Podder Jun 19 '16 at 20:28
  • I still use eclipse :( – Sudip Podder Jun 19 '16 at 20:37
  • Where did you run this code ? What dependencies did you use ? Just walk me through please this is my very first location based app.. – Dwijraj Bhattacharya Jun 19 '16 at 20:37
  • dont know much about android studio. as you are using emulator, you can try to install latest google play services in your emulator from this link: http://hmkcode.com/run-google-map-v2-on-android-emulator/ . if possible, please get a real android device, set up your phone's driver in your pc and use your phone as emulator. you wont face the issue you addressed in a real device – Sudip Podder Jun 19 '16 at 21:21
  • I tried running my app on HTC 626gplus and Samsung Tab A still doesnot work...give the manifest file ? – Dwijraj Bhattacharya Jun 20 '16 at 07:07
  • did you get the exact same error in your real devices? if yes, then make sure the google play services in your phone is up-to-date. and there is nothing special in the manifest, just the compulsory meta-data part. cant provide it right now, will take a few hours :( – Sudip Podder Jun 20 '16 at 07:48
  • Just tell me if the manifest file is ok ..here are the attributes i put – Dwijraj Bhattacharya Jun 20 '16 at 10:03
0

It looks like the version of Google Play Services that you're building your app with is higher than the version you currently have installed on your test device, as previously answered here:

When does isGooglePlayServicesAvailable return SERVICE_VERSION_UPDATE_REQUIRED?

Community
  • 1
  • 1
jeevcat
  • 343
  • 2
  • 12