1

I have am stuck in this issue for last couple of days. This is my first app ever, so I may have made a silly mistake that I cant figure out.

I am making a simple webView multiplayer realtime game using android play games and re-engineering android sample's ButtonClicker2000 game. However when I invite a player, I am not able to see any invites. The invitation and the room creation is apparently successful( all the right logs/toasts are shown). However when I look at the pending invites (invite inbox) then the response from onActivityResult is 0 instead of Activity.RESULT_OK or -1.

SORRY IF THE CODE IS TOO LONG. JUST THOUGHT I WILL PASTE ALL RELEVANT PARTS

Relevant code is: Here invitePlayers and seeInvites are the relevant cases.

@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;
    }
}

When I get response back: (RC_SELECT_PLAYERS is the relevant switch case)

   @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);
    }

Finally the functions to handle the invites:

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());
}
user1517108
  • 2,395
  • 6
  • 32
  • 43

1 Answers1

0

Well the error was that I had not enabled multiplayer in Google Console for developers. The difference between the colors of Off and On switch was significant , and I thought that I had switched it ON, but it was off p-)

user1517108
  • 2,395
  • 6
  • 32
  • 43
  • The question is so old, and i guess you have got so much experience with GPGS RTMP by now... so i thought you might be able to answer my [Question](https://stackoverflow.com/questions/52739109/google-play-games-realtime-multiplayer-getting-participant-id-and-storing-it-to), it would be great. – Sumit Pal Oct 11 '18 at 09:55