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:

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

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

@Override
protected void onStart() {
    super.onStart();
    mGoogleApiClient.connect();
}

@Override
protected void onStop() {
    super.onStop();
    mGoogleApiClient.disconnect();
}


@Override
public void onConnected(Bundle bundle) {
    Log.i("Result", "onConnected");
}

@Override
public void onConnectionSuspended(int i) {
    // Attempt to reconnect
    mGoogleApiClient.connect();
}

@Override
public void onConnectionFailed(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 picker
    try {
        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 here enter 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"