Android游戏-实时多人游戏-邀请无效

Android游戏-实时多人游戏-邀请无效,android,google-play-games,Android,Google Play Games,过去几天我一直在讨论这个问题。这是我有史以来的第一个应用程序,所以我可能犯了一个我无法理解的愚蠢错误 我正在使用android play游戏和重新设计ButtonClicker2000游戏制作一个简单的webView多人实时游戏。但是,当我邀请一个玩家时,我无法看到任何邀请。邀请和房间创建显然是成功的(显示了所有正确的日志/祝酒词)。但是,当我查看挂起的邀请(邀请收件箱)时,ActivityResult上的响应是0,而不是活动。结果\u OK或-1 如果代码太长,很抱歉。我只是想粘贴所有相关部分

过去几天我一直在讨论这个问题。这是我有史以来的第一个应用程序,所以我可能犯了一个我无法理解的愚蠢错误

我正在使用android play游戏和重新设计ButtonClicker2000游戏制作一个简单的webView多人实时游戏。但是,当我邀请一个玩家时,我无法看到任何邀请。邀请和房间创建显然是成功的(显示了所有正确的日志/祝酒词)。但是,当我查看挂起的邀请(邀请收件箱)时,ActivityResult上的
响应是0,而不是
活动。结果\u OK
或-1

如果代码太长,很抱歉。我只是想粘贴所有相关部分

有关守则如下: 这里的
invitePlayers
seeInvites
是相关案例

@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\u SELECT\u PLAYERS
是相关的切换案例)

最后是处理邀请的函数:

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());
}
private void handleSelectPlayersResult(int响应、意图数据){
如果(响应!=活动结果\u正常){
Toast.makeText(getApplicationContext(),“***选择播放器UI已取消,”+响应,Toast.LENGTH_LONG).show();
切换到屏幕();
返回;
}
Toast.makeText(getApplicationContext(),“选择玩家UI成功”,Toast.LENGTH\u LONG.show();
//获取被邀请者列表
最终ArrayList invites=data.getStringArrayListXTRA(Games.EXTRA\u PLAYER\u id);
Toast.makeText(getApplicationContext(),“被邀请者计数:”+invitees.size(),Toast.LENGTH\u LONG.show();
//获取automatch标准
Bundle autoMatchCriteria=null;
int minAutoMatchPlayers=data.getIntExtra(Multiplayer.EXTRA\u MIN\u AUTOMATCH\u PLAYERS,0);
int maxAutoMatchPlayers=data.getIntExtra(Multiplayer.EXTRA\u MAX\u AUTOMATCH\u PLAYERS,0);
如果(MinAutoMatchPlayer>0 | | MaxAutomatchPlayer>0){
autoMatchCriteria=RoomConfig.createAutoMatchCriteria(
MinAutoMatchPlayer,MaxAutomatchPlayer,0);
Toast.makeText(getApplicationContext(),“Automatch条件:”+autoMatchCriteria,Toast.LENGTH_LONG).show();
}
//创建房间
Toast.makeText(getApplicationContext(),“创建房间…”,Toast.LENGTH_LONG.show();
RoomConfig.Builder rtmConfigBuilder=RoomConfig.Builder(此);
rtmConfigBuilder.addPlayersToInvite(被邀请者);
rtmConfigBuilder.setMessageReceivedListener(此);
rtmConfigBuilder.setRoomStatusUpdateListener(此);
如果(条件!=null){
rtmConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
}
//切换到屏幕(R.id.screen\u wait);
keepScreenOn();
重置游戏变量();
创建(mGoogleApiClient,rtmConfigBuilder.build());
Toast.makeText(getApplicationContext(),“房间已创建,等待准备就绪…”,Toast.LENGTH_LONG.show();
}
//处理邀请收件箱UI的结果,玩家可以在其中选择邀请
//接受。我们的反应是接受所选的邀请(如果有的话)。
私有void handleInvitationInboxResult(int响应、意图数据){
如果(响应!=活动结果\u正常){
Toast.makeText(getApplicationContext(),“***邀请收件箱UI已取消,”+响应,Toast.LENGTH_LONG).show();
切换到屏幕();
返回;
}
Toast.makeText(getApplicationContext(),“邀请收件箱UI成功”,Toast.LENGTH\u LONG.show();
邀请inv=data.getExtras().getParcelable(多人游戏.EXTRA\u邀请);
//接受邀请
acceptInviteToRoom(inv.getInvitationId());
}
//接受给定的邀请。
void acceptInviteToRoom(字符串invId){
//接受邀请
Toast.makeText(getApplicationContext(),“接受邀请:”+invId,Toast.LENGTH\u LONG.show();
RoomConfig.Builder roomConfigBuilder=RoomConfig.Builder(此);
roomConfigBuilder.setInvitationIdToAccept(因维德)
.setMessageReceivedListener(此)
.setRoomStatusUpdateListener(此文件);
//切换到屏幕(R.id.screen\u wait);
keepScreenOn();
重置游戏变量();
Games.RealTimeMultiplayer.join(mGoogleApiClient,roomConfigBuilder.build());
}

错误在于我没有在谷歌控制台中为开发者启用多人游戏。关闭和打开开关的颜色差异很大,我以为我已经打开了,但它是关闭的p-

错误在于我没有在谷歌控制台中为开发者启用多人游戏。关闭和打开开关的颜色差异很大,我以为我已经打开了,但它是关闭的p-

这个问题太老了,我想你现在已经有了很多GPGS RTMP的经验。。。所以我想你也许能回答我的问题,那太好了。这个问题太老了,我想你现在已经有了很多GPGS RTMP的经验。。。所以我想你也许能回答我的问题,那太好了。
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());
}