Skip to content Skip to sidebar Skip to footer

Sign-in With Google For Games Services

I am implementing the new sign in with google flow according to this blog post: api-updates-for-sign-in-with-google However on sign in I get the following exception: IllegalStateEx

Solution 1:

IMO, you can refer to the following sample code:

...
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_games);

    mGoogleApiClient = newGoogleApiClient.Builder(this)
            .enableAutoManage(this, this)
            .addApi(Games.API).addScope(Games.SCOPE_GAMES)
            .build();
}

@OverrideprotectedvoidonStart() {
    super.onStart();
    mGoogleApiClient.connect();
}

@OverrideprotectedvoidonStop() {
    super.onStop();
    mGoogleApiClient.disconnect();
}


@OverridepublicvoidonConnected(Bundle bundle) {
    Log.i("Result", "onConnected");
}

@OverridepublicvoidonConnectionSuspended(int i) {
    // Attempt to reconnect
    mGoogleApiClient.connect();
}

@OverridepublicvoidonConnectionFailed(ConnectionResult connectionResult) {
    Log.e("Result", "onConnectionFailed");

    // If the connection failed, in most of time this means user hasn't logined yet// In this case invoke the `startResolutionForResult` will launch the login dialog and account pickertry {
        if (connectionResult.hasResolution()) {
            connectionResult.startResolutionForResult(m_activity, RC_SIGN_IN);
        }
    } catch (IntentSender.SendIntentException e) {
        e.printStackTrace();
    }
}
...

More details at Accessing the Play Games Services APIs in Your Android Game

If your app gets java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information, please read Troubleshooting Issues in Your Android Game

Some screenshots:

enter image description hereenter image description here

Solution 2:

There is a similar error that was ask in this community.

The error message seems pretty clear that this isn't possible at the moment: Games has its own login flow. Is there a particular reason you are using both?

Here is a reference on Implementing Sign-in In Your Games.

Post a Comment for "Sign-in With Google For Games Services"