我正在开发一个游戏为Android使用谷歌玩游戏服务,使用Xamarin。我做用Genymotion Android模拟器我的测试。我遇到了,似乎在任谷歌播放或Xamarin的实现中的错误问题。
I am developing a game for Android using Google Play Game Services, using Xamarin. I am doing my testing using a Genymotion Android Emulator. I have run into an issue that appears to be a bug in either Google Play or Xamarin's implementation.
如果我签了一个谷歌帐户的,则调用 IGoogleApiClient.IsConnected()继续返回true (即使我有显然刚刚签署了)。如果我再尝试使用该API的对象,我会得到这样的例外:
If I sign out of a Google account, calls to the IGoogleApiClient.IsConnected() continue to return true (even though I have clearly just signed out). If I then attempt to use that API object, I will get exceptions like:
java.lang.SecurityException异常:未签订调用API时
java.lang.SecurityException: Not signed in when calling API
例如,在上面的异常后续code的结果,如果注销后执行:
For example, the follow code results in the above exception if executed after signing out:
public void StartNewMatch()
{
if (!mGoogleApiClient.IsConnected)
{
return;
}
Intent intent = GamesClass.TurnBasedMultiplayer.GetSelectOpponentsIntent(mGoogleApiClient, 1, 1, true);
StartActivityForResult(intent, RC_SELECT_PLAYERS);
}
我签署了在谷歌Play游戏收件箱(匹配选择器);如下面的图像。
I am signing out in the Google Play Games Inbox (match picker); as shown in the images below.
任何人都碰到过?我失去了一些东西?有任何变通办法?
Anyone run into this before? Am I missing something? Got any work-arounds?
注意:这种情况只发生,如果注销通过谷歌的用户界面如果我手动登录用户了,有像 mGoogleApiClient.Disconnect(),这个问题不会出现;
mGoogleApiClient.IsConnected()
现在返回false(如预期)。
Note: This only occurs if signing out through Google's UI. If I manually sign the user out, with something like mGoogleApiClient.Disconnect()
, the issue does not occur; mGoogleApiClient.IsConnected()
now returns false (as expected).
推荐答案
为了保持登录的状态同步增长就必须实现onActivityResult正常。
In order to keep signed-in state synced up you MUST implement onActivityResult properly.
这看起来应该是如下:
请注意:这是java的code,我不知道这将如何看起来完全使用Xamarin,但希望你应该能够理解它:)
NOTE: this is java code, I am not sure how this will look exactly using Xamarin, but hopefully you should be able to figure it out :)
@Override
protected void onActivityResult(int requestCode, int responseCode, Intent data) {
// check for "inconsistent state"
if ( responseCode == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED && requestCode == <your_request_code_here> ) {
// force a disconnect to sync up state, ensuring that mClient reports "not connected"
mGoogleApiClient.disconnect();
}
}
请注意:只要确保替换code与你使用的请求code。您可能需要检查多个请求codeS了。
NOTE: just make sure to replace in the code with the request code you used. You may need to check for multiple request codes too.
相关推荐
最新文章