L3n95
L3n95

Reputation: 1615

Android: Use Wear API and Games API

I have a GoogleApiClient. I use this code:

GoogleApiClient client = new GoogleApiClient.Builder(this).addApi(Games.API).addScope(Games.SCOPE_GAMES).addApiIfAvailable(Wearable.API).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();

I have stored a boolean in SharedPrefs if the user wanted to connect with Google Play Games. If yes I call client.connect(). But if not I still want, that the Wearable API is connected. How can I achieve, that the Wearable API will be always connected, but the Games API not.

Upvotes: 0

Views: 133

Answers (1)

Sterling
Sterling

Reputation: 6635

Why not simply connect to the Games API conditionally, based on the SharedPreference?

GoogleApiClient.Builder bob = new GoogleApiClient.Builder(this)
        .addApiIfAvailable(Wearable.API)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this);
if (settings.getBoolean("use_games", false)) {
    bob.addApi(Games.API)
            .addScope(Games.SCOPE_GAMES);
}
GoogleApiClient client = bob.build();

Based on your question, that seems like the obvious approach. Or am I missing something here?

Upvotes: 2

Related Questions