如何解决丢失的Google Multiplayer RealTime邀请

时间:2019-02-06 08:53:07

标签: android google-play google-signin google-play-games google-realtime-api

有时,缺少来自Google Play游戏的接受邀请。目前,我使用的是Google实时多人游戏指南中的代码,并在缺少提示时添加了备份检查以手动加载邀请列表。 如何重现此行为:

  1. 如果用户暂时不使用该应用程序或当前未登录
  2. 用户在Google Play游戏应用中接收并接受实时多人游戏邀请
  3. Google Play游戏打开应用
  4. 用户登录或将自动以静默方式登录
  5. 使用已使用的GoogleSignInAccount调用
  6. onConnected
  7. 缺少多人游戏。EXTRA_INVITATION


private void checkForInvitation()
{
    if (mSignedInAccount == null) {
        return;
    }

    Games.getGamesClient(context(), mSignedInAccount)
    .getActivationHint()
    .addOnSuccessListener(
                        new OnSuccessListener<Bundle>() {
                              @Override
                              public void onSuccess(Bundle bundle) {

                                  if (bundle != null) {
                                      Invitation invitation = bundle.getParcelable(Multiplayer.EXTRA_INVITATION);
                                      if (invitation != null) {
                                          //... do something with the invitation
                                          return;
                                      }
                                  }

                                  checkForInvitationBackup();
                              }
                        }).addOnFailureListener(createFailureListener("There was a problem getting the activation hint!"));
}

private void checkForInvitationBackup()
{
    if (mInvitationsClient == null) return;

    mInvitationsClient.loadInvitations().addOnSuccessListener(new OnSuccessListener<AnnotatedData<InvitationBuffer>>() {
        @Override
        public void onSuccess(AnnotatedData<InvitationBuffer> invitationBufferAnnotatedData)
        {

            if (invitationBufferAnnotatedData != null) {

                InvitationBuffer invitationBuffer = invitationBufferAnnotatedData.get();
                if (invitationBuffer != null) {

                    if (invitationBuffer.getCount() > 0) {
                        Invitation invitation = invitationBuffer.get(0);
                        if (invitation != null) {
                            //... do something with the invitation
                        }
                    }
                }
            }
        }
    }).addOnFailureListener(createFailureListener("There was a problem getting the invitation list."));
}

为什么捆绑商品为空,有时却不是?我该如何更好地处理它?<​​/ p>

0 个答案:

没有答案