Scrungepipes
Scrungepipes

Reputation: 37590

GoogleApiClient.ConnectionCallbacks methods not being called after connecting to the GoogleApiClient

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?

Upvotes: 0

Views: 6092

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 200110

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

mApiClient = new GoogleApiClient.Builder( this )
    .addApi( Wearable.API )
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this)
    .build();

Upvotes: 5

Related Questions