如何确定从Google Play游戏循环播放通知中选择的匹配项

Eoi*_*oin 3 android google-play-games

当用户接收并点击基于回合的通知时,弹出默认UI,允许他们选择继续转向/邀请.然后启动我的游戏.

但是我无法弄清楚如何确定哪个转弯/邀请用户选择并自动加载相应的匹配.

目前,我被迫重新展示默认匹配的收件箱用户界面,并对其进行反应.

小智 5

我有这个

TurnBasedMatch aMatch = getGameHelper().getTurnBasedMatch();
if (aMatch != null) {
    // GameHelper will cache any connection hint it gets. In this case,
    // it can cache a TurnBasedMatch that it got from choosing a
    // turn-based
    // game notification. If that's the case, you should go straight
    // into
    // the game.
    updateMatch(aMatch);
    return;
}
Run Code Online (Sandbox Code Playgroud)

在我的主要活动中,我刚刚在示例SkeletonActivity中找到它,我必须从中复制它.我们的想法是,当你的主要活动被启动时,如果你使用了标准的BaseGameActivity基类,它会自动进行身份验证和登录,一旦登录,Game Helper实例就可以从任何外部诱导的意图中检索匹配或提示可用.

此GameHelper类是快速入门指南建议使用的BaseGameUtils"库"的一部分.此GameHelper从客户端库的onConnected()中提供的Bundle中获取匹配.

TurnBasedMatch match = connectionHint
    .getParcelable(GamesClient.EXTRA_TURN_BASED_MATCH);
Run Code Online (Sandbox Code Playgroud)

  • 在处理通知中的"存储"游戏后,您可能希望在GameHelper对象上调用clearTurnBasedMatch().在我的游戏中我必须这样做,因为否则每次重新进入游戏时都会加载相同的游戏. (2认同)