简体   繁体   English

用户退出Google Play游戏服务

[英]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? 当用户明确退出Google Play游戏服务时,我认为他们想保持退出状态,但是如何确定他们是否已退出呢?

When I sign out, the onActivityResult() resultCode is 10001 which is defined as : 当我注销时, onActivityResult() resultCode10001 ,其定义为

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. GoogleApiClient处于不一致状态,必须重新连接到服务才能解决问题。 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? 所以我的问题是:我如何确定用户已明确退出我的应用程序的Google Play游戏?

Based on the Games API documentation (linked below), you can use the Games.signOut() API to asynchronously sign out the current user. 根据Games API文档(下面链接),您可以使用Games.signOut()API异步注销当前用户。

Hopefully this will be the appropriate API to use for your scenario. 希望这将是适合您的方案的API。

https://developers.google.com/android/reference/com/google/android/gms/games/Games.html#signOut(com.google.android.gms.common.api.GoogleApiClient) 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). 您要从“游戏”活动中获取结果代码的唯一原因是,如果用户已通过Google提供的用户界面退出(除非发生任何非常奇怪的事情)。 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. 但是,如果您要进行检查-您可以尝试将GoogleApiClient与Games API重新连接。 If the user has explicitly signed out, this will always fail with the result SIGN_IN_REQUIRED. 如果用户已明确注销,则将始终失败,并显示结果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. 正如@TimSim所提到的,如果想在游戏中提供注销功能,则可以使用Games.signOut API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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