简体   繁体   中英

Detecting user backing out of Google Play Games Login

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?

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..
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM