适用于回合制游戏的Android Google Play服务,无法通过默认用户界面接收邀请

时间:2014-04-18 05:09:06

标签: android google-play-services

我是新手,基于游戏开发并尝试开发基于回合制的游戏。我使用默认UI来选择玩家

Intent intent = Games.TurnBasedMultiplayer.getSelectOpponentsIntent(getApiClient(), 1, 1, true);
startActivityForResult(intent, RC_SELECT_PLAYERS);

当我选择玩家沙子说Play时,其他玩家应该得到通知。但该播放器未收到邀请/通知。

@Override
public void onSignInSucceeded() {

    updateLayouts();   

    Games.Invitations.registerInvitationListener(getApiClient(), this);
            // developer document says that above line is not required
            // include or exclude for me it is not making any difference

}

@Override
public void onInvitationReceived(Invitation invitation) {
    Toast.makeText(
            this,
            "An invitation has arrived from "
                    + invitation.getInviter().getDisplayName(), Toast.LENGTH_LONG)
                    .show();

    Log.d(TAG, "Invitation arrived from " + invitation.getInviter().getDisplayName());



}

这是我的onActivtityResult

@Override
public void onActivityResult(int request, int response, Intent data) {
    super.onActivityResult(request, response, data);

    if (request == RC_LOOK_AT_MATCHES) {
        // Returning from the 'Select Match' dialog

        if (response != Activity.RESULT_OK) {
            // user canceled
            return;
        }

        TurnBasedMatch match = data
                .getParcelableExtra(com.google.android.gms.games.multiplayer.Multiplayer.EXTRA_TURN_BASED_MATCH);

        if (match != null) {
            updateMatch(match);
        }

        Log.d(TAG, "Match = " + match);
    } 
    else if (request == RC_SELECT_PLAYERS) {
        if (response != Activity.RESULT_OK) {
            // user canceled
            return;
        }

        // get the invitee list
        final ArrayList<String> invitees =
                data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);

        Log.d(TAG, "Invitees count = " + invitees.size());
        for(int i=0; i<invitees.size(); i++){
            Log.d(TAG, invitees.get(i));
        }

        // get auto-match 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) {
            autoMatchCriteria
            = RoomConfig.createAutoMatchCriteria(
                    minAutoMatchPlayers, maxAutoMatchPlayers, 0);

            Log.d(TAG, "minAutoMatchPlayers > 0");

        } else {
            autoMatchCriteria = null;
            Log.d(TAG, "minAutoMatchPlayers <= 0");
        }

        TurnBasedMatchConfig tbmc = TurnBasedMatchConfig.builder()
                .addInvitedPlayers(invitees)                    
                .setAutoMatchCriteria(autoMatchCriteria).build();


        // kick the match off
        Games.TurnBasedMultiplayer
        .createMatch(getApiClient(), tbmc)
        .setResultCallback(new ResultCallback<TurnBasedMultiplayer.InitiateMatchResult>() {
            @Override
            public void onResult(TurnBasedMultiplayer.InitiateMatchResult result) {
                processResult(result);
            }
        });

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        showSpinner();
    }
}

有谁能告诉我哪里出错了?

2 个答案:

答案 0 :(得分:2)

通知发生在第一个玩家(创建比赛的人)轮到他后,通过调用Games.TurnBasedMultiplayer.takeTurn()而不是马上创建比赛后立即发生。

答案 1 :(得分:0)

也可以尝试this。如果没有邀请(即使您的应用已关闭),account-lvl限制也会阻止它们。