0

I've got some code which is connecting to the GoogleApiClient but onConnected is not being called.

public class MainActivity extends Activity implements  GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
    private GoogleApiClient mApiClient;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initGoogleApiClient();
    }

    private void initGoogleApiClient() {
        mApiClient = new GoogleApiClient.Builder( this )
                .addApi( Wearable.API )
                .build();
        mApiClient.connect(); // On completion onConnected() will be called
    }
    @Override
    public void onConnected(Bundle bundle) {
    }

    @Override
    public void onConnectionSuspended(int i) {
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mApiClient.disconnect();
    }

    @Override
    public void onConnectionFailed(com.google.android.gms.common.ConnectionResult connectionResult) {
    }

None of the four @Override methods are being called, why is that?

Gruntcakes
  • 37,738
  • 44
  • 184
  • 378

1 Answers1

5

You need to call addConnectionCallbacks() and addOnConnectionFailedListener() on your GoogleApiClient.Builder:

mApiClient = new GoogleApiClient.Builder( this )
    .addApi( Wearable.API )
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this)
    .build();
ianhanniballake
  • 191,609
  • 30
  • 470
  • 443