2016-03-07 151 views
1

我已經是卡在這個問題上的最後幾天。這是我的第一個應用程序,所以我可能犯了一個愚蠢的錯誤,我不知道。Android遊戲玩 - 實時多人遊戲 - 邀請不工作

我正在採用了android玩遊戲和重新設計android sample's ButtonClicker2000遊戲簡單的web視圖多人實時遊戲。但是,當我邀請玩家時,我無法看到任何邀請。邀請和房間創作顯然是成功的(所有正確的日誌/祝酒都顯示出來)。然而,當我看待處理的邀請(INVITE收件箱),然後從onActivityResult的響應是0而不是Activity.RESULT_OK或-1。

SORRY如果代碼太長。只是想我會糊所有相關部分

相關代碼: 這裏invitePlayersseeInvites是相關的情況。

@JavascriptInterface 
public void multiButtonFunction (String typeButton) { 
    Intent intent; 
    switch (typeButton) { 
     case "signin": 
      // start the sign-in flow 
      if (!verifySampleSetup(this, R.string.app_id)) { 
       Log.w(TAG, "*** Warning: setup problems detected. Sign in may not work!"); 
      } 
      Toast.makeText(getApplicationContext(), "Sign-in button clicked0", Toast.LENGTH_LONG).show(); 
      mSignInClicked = true; 
      mGoogleApiClient.connect(); 
      break; 
     case "signout": 
      // start the sign-out flow 
      Toast.makeText(getApplicationContext(), "Sign-Out button clicked0", Toast.LENGTH_LONG).show(); 
      mSignInClicked = false; 
      Games.signOut(mGoogleApiClient); 
      mGoogleApiClient.disconnect(); 
      break; 
     case "invitePlayers": 
      // show list of invitable players 
      intent = Games.RealTimeMultiplayer.getSelectOpponentsIntent(mGoogleApiClient, 1, 3); 
      switchToScreen(0); 
      startActivityForResult(intent, RC_SELECT_PLAYERS); 
      break; 
     case "seeInvites": 
      // show list of pending invitations 
      intent = Games.Invitations.getInvitationInboxIntent(mGoogleApiClient); 
      startActivityForResult(intent, RC_INVITATION_INBOX); 
     case "acceptInvites": 
      // user wants to accept the invitation shown on the invitation popup 
      // (the one we got through the OnInvitationReceivedListener). 
      acceptInviteToRoom(mIncomingInvitationId); 
      mIncomingInvitationId = null; 
      break; 
     case "quickGame": 
      // user wants to play against a random opponent right now 
      startQuickGame(); 
      break; 
    } 
} 

當我返回響應:(RC_SELECT_PLAYERS是相關的開關情況)

@Override 
    public void onActivityResult(int requestCode, int responseCode, 
           Intent intent) { 
     super.onActivityResult(requestCode, responseCode, intent); 

     switch (requestCode) { 
      case RC_SELECT_PLAYERS: 
       // we got the result from the "select players" UI -- ready to create the room 
       handleSelectPlayersResult(responseCode, intent); 
       break; 
      case RC_INVITATION_INBOX: 
       // we got the result from the "select invitation" UI (invitation inbox). We're 
       // ready to accept the selected invitation: 
       handleInvitationInboxResult(responseCode, intent); 
       break; 
      case RC_WAITING_ROOM: 
       // we got the result from the "waiting room" UI. 
       if (responseCode == Activity.RESULT_OK) { 
        startGame(true); 
       } else if (responseCode == GamesActivityResultCodes.RESULT_LEFT_ROOM) { 
        leaveRoom(); 
       } else if (responseCode == Activity.RESULT_CANCELED) { 
        leaveRoom(); 
       } 
       break; 
      case RC_SIGN_IN: 
       Log.d(TAG, "onActivityResult with requestCode == RC_SIGN_IN, responseCode="+ responseCode + ", intent=" + intent); 
       Toast.makeText(getApplicationContext(), "onActivityResult with requestCode == RC_SIGN_IN, responseCode="+ responseCode + ", intent=" + intent, Toast.LENGTH_LONG).show(); 
       mSignInClicked = false; 
       mResolvingConnectionFailure = false; 
       if (responseCode == RESULT_OK) { 
        mGoogleApiClient.connect(); 
       } else { 
        //BaseGameUtils.showActivityResultError(this,requestCode,responseCode, R.string.signin_other_error); 
        (new AlertDialog.Builder(this)) 
          .setTitle(responseCode) 
          .setMessage(R.string.signin_other_error) 
          .setNeutralButton(android.R.string.ok, null) 
          .create(); 
       } 
       break; 
     } 
     super.onActivityResult(requestCode, responseCode, intent); 
    } 

最後的函數來處理的邀請:

private void handleSelectPlayersResult(int response, Intent data) { 
    if (response != Activity.RESULT_OK) { 
     Toast.makeText(getApplicationContext(), "*** select players UI cancelled, " + response, Toast.LENGTH_LONG).show(); 
     switchToMainScreen(); 
     return; 
    } 
    Toast.makeText(getApplicationContext(), "Select players UI succeeded.", Toast.LENGTH_LONG).show(); 

    // get the invitee list 
    final ArrayList<String> invitees = data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS); 
    Toast.makeText(getApplicationContext(),"Invitee count: " + invitees.size(), Toast.LENGTH_LONG).show(); 

    // get the automatch criteria 
    Bundle autoMatchCriteria = null; 
    int minAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0); 
    int maxAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0); 
    if (minAutoMatchPlayers > 0 || maxAutoMatchPlayers > 0) { 
     autoMatchCriteria = RoomConfig.createAutoMatchCriteria(
       minAutoMatchPlayers, maxAutoMatchPlayers, 0); 
     Toast.makeText(getApplicationContext(),"Automatch criteria: " + autoMatchCriteria, Toast.LENGTH_LONG).show(); 
    } 

    // create the room 
    Toast.makeText(getApplicationContext(), "Creating room...", Toast.LENGTH_LONG).show(); 
    RoomConfig.Builder rtmConfigBuilder = RoomConfig.builder(this); 
    rtmConfigBuilder.addPlayersToInvite(invitees); 
    rtmConfigBuilder.setMessageReceivedListener(this); 
    rtmConfigBuilder.setRoomStatusUpdateListener(this); 
    if (autoMatchCriteria != null) { 
     rtmConfigBuilder.setAutoMatchCriteria(autoMatchCriteria); 
    } 
    //switchToScreen(R.id.screen_wait); 
    keepScreenOn(); 
    resetGameVars(); 
    Games.RealTimeMultiplayer.create(mGoogleApiClient, rtmConfigBuilder.build()); 
    Toast.makeText(getApplicationContext(), "Room created, waiting for it to be ready...", Toast.LENGTH_LONG).show(); 
} 
// Handle the result of the invitation inbox UI, where the player can pick an invitation 
// to accept. We react by accepting the selected invitation, if any. 
private void handleInvitationInboxResult(int response, Intent data) { 
    if (response != Activity.RESULT_OK) { 
     Toast.makeText(getApplicationContext(), "*** invitation inbox UI cancelled, " + response, Toast.LENGTH_LONG).show(); 
     switchToMainScreen(); 
     return; 
    } 
    Toast.makeText(getApplicationContext(), "Invitation inbox UI succeeded.", Toast.LENGTH_LONG).show(); 
    Invitation inv = data.getExtras().getParcelable(Multiplayer.EXTRA_INVITATION); 

    // accept invitation 
    acceptInviteToRoom(inv.getInvitationId()); 
} 
// Accept the given invitation. 
void acceptInviteToRoom(String invId) { 
    // accept the invitation 
    Toast.makeText(getApplicationContext(), "Accepting invitation: " + invId, Toast.LENGTH_LONG).show(); 
    RoomConfig.Builder roomConfigBuilder = RoomConfig.builder(this); 
    roomConfigBuilder.setInvitationIdToAccept(invId) 
      .setMessageReceivedListener(this) 
      .setRoomStatusUpdateListener(this); 
    //switchToScreen(R.id.screen_wait); 
    keepScreenOn(); 
    resetGameVars(); 
    Games.RealTimeMultiplayer.join(mGoogleApiClient, roomConfigBuilder.build()); 
} 

回答

0

那麼錯誤是,我不得不未在Google控制檯中爲開發者啓用多人遊戲。關和ON開關顏色之間的差異是顯著的,我認爲我有交換,但它是關閉對)