简体   繁体   中英

User sign out of Google Play Games Services

When the user explicitly signs out of Google Play Games Services, I assume they want to stay signed out, but how do I find out if they've done this?

When I sign out, the onActivityResult() resultCode is 10001 which is defined as :

Result code sent back to the calling Activity when a reconnect is required.

The GoogleApiClient is in an inconsistent state and must reconnect to the service to resolve the issue. Further calls to the service using the current connection are unlikely to succeed.

I'm not sure if it's safe to consider this result code as explicit sign out, or if it can happen in other situations where the user doesn't want to stay signed out.

So my question is: how do I know for sure the user has explicitly signed out of Google Play Games for my app?

Based on the Games API documentation (linked below), you can use the Games.signOut() API to asynchronously sign out the current user.

Hopefully this will be the appropriate API to use for your scenario.

https://developers.google.com/android/reference/com/google/android/gms/games/Games.html#signOut(com.google.android.gms.common.api.GoogleApiClient)

The only reason you'd get back that result code from a Games activity is if the user has signed out via the Google-provided UI (barring anything very weird happening). So in that case, you can reasonably assume the user is signed out.

However, if you want to check this - you can attempt to reconnect the GoogleApiClient with a Games API. If the user has explicitly signed out, this will always fail with the result SIGN_IN_REQUIRED.

And as @TimSim mentions, you can use the Games.signOut API if you want to provide sign-out functionality from within your game.

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