Google Play游戏服务,自动匹配结果数据中未包含的玩家信息

时间:2013-09-22 03:57:45

标签: android google-play-games

我使用Google Play游戏服务制作了一个简单的示例游戏应用程序。

在代码中,我使用GameClient.getSelectPayersIntent()方法启动了播放器选择屏幕,就像示例一样。

 intent = getGamesClient().getSelectPlayersIntent(1, 3);
 showScreen(Screen.WAITING);
 startActivityForResult(intent, RC_SELECT_PLAYERS);

玩家选择活动返回了结果数据,但即使我选择了两个自动匹配玩家,也不会包含GamesClient.EXTRA_PLAYERSGamesClient.EXTRA_MIN_AUTOMATCH_PLAYERSGamesClient.EXTRA_MAX_AUTOMATCH_PLAYERS个额外内容。

当我调试它时,它只在其额外的地图中保留com.google.android.gms.games.MAX_SELECTIONcom.google.android.gms.games.MIN_SELECTION个额外内容。

getSelectPlayersIntent的javadoc中,结果应包含所选的玩家信息。

我是否需要为此功能进行一些设置?

这是我的onActivityResult代码。我只是从样本中复制了它。

@Override
protected void onActivityResult(int requestCode, int responseCode, Intent data) {
    super.onActivityResult(requestCode, responseCode, data);
    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;
        ... other stuffs


private void handleSelectPlayersResult(int response, Intent data) {
    if (response != Activity.RESULT_OK) {
        Log.w(TAG, "*** select players UI cancelled, " + response);
        showScreen(Screen.MAIN);
        return;
    }

    Log.d(TAG, "Select players UI succeeded.");

    // get the invitee list
    final ArrayList<String> invitees = data.getStringArrayListExtra(GamesClient.EXTRA_PLAYERS);
    if (invitees != null) {
        Log.d(TAG, "Invitee count: " + invitees.size());
    }

    // get the automatch criteria
    Bundle autoMatchCriteria = null;
    int minAutoMatchPlayers = data.getIntExtra(GamesClient.EXTRA_MIN_AUTOMATCH_PLAYERS, 0);
    int maxAutoMatchPlayers = data.getIntExtra(GamesClient.EXTRA_MAX_AUTOMATCH_PLAYERS, 0);
    if (minAutoMatchPlayers > 0 || maxAutoMatchPlayers > 0) {
        autoMatchCriteria = RoomConfig.createAutoMatchCriteria(
                minAutoMatchPlayers, maxAutoMatchPlayers, 0);
        Log.d(TAG, "Automatch criteria: " + autoMatchCriteria);
    }

    // create the room
    Log.d(TAG, "Creating room...");
    RoomConfig.Builder rtmConfigBuilder = RoomConfig.builder(this);
    if (invitees != null) {
        rtmConfigBuilder.addPlayersToInvite(invitees);
    }
    rtmConfigBuilder.setMessageReceivedListener(this);
    rtmConfigBuilder.setRoomStatusUpdateListener(this);
    if (autoMatchCriteria != null) {
        rtmConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
    }
    showScreen(Screen.WAITING);
    keepScreenOn();
    getGamesClient().createRoom(rtmConfigBuilder.build());
    Log.d(TAG, "Room created, waiting for it to be ready...");
}

更新

哎呀,这是我的错。我使用发送的意图,没有收到数据意图。

0 个答案:

没有答案