Detecting user backing out of Google Play Games Login

192 views Asked by At

In a game with auto-sign in, if the user presses the 'cancel' button when prompted to log in to Play Games, how can we detect that the user actually pressed the cancel button?

Google changed the way players log into Google Play Games Services and previously I was checking in onActivityResult for the result code. something like this:

protected void onActivityResult(int request, int resultCode, Intent data) {
    
    if (request == RC_SIGN_IN){

        if(resultCode==0){
            //User has aborted sign in, so show dialog and set flags to stop
            //Auto sign in here
        }
    }
}

However, since things have changed, when pressing cancel, it now returns 10002 which, according to the Docs, means..... (emphasis added by me)

Result code sent back to the calling Activity when signing in fails.

The attempt to sign in to the Games service failed. For example, this might happen if the network is flaky, or the user's account has been disabled, or consent could not be obtained.

So, when I check for a result code of 10002, I can then put my code in there to disable auto sign-in, however, if the network connection is 'flaky' or some other problem, I don't want to do this - only when the user backs out.....

How can this be achieved?

1

There are 1 answers

0
ReyAnthonyRenacia On

I think there are listeners and methods for connection errors like onConnectionFailed() as mentioned in the Handling Connections failures guide.

The cancel reponse can be placed in an else condition:

@@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        handleSignInResult(result);
    } else if(resultCode == RESULT_CANCELED){
      // Do something when user clicks Cancel..
    }
}