从未发送过Google Play游戏服务消息

时间:2018-09-05 10:14:27

标签: java android google-play-services google-play-games

我在使用Google Play游戏服务API时遇到问题。我正确地获得了GoogleSignAccount。然后,我打开一个房间,创建一个RealtimeMultiplayerClient。当我尝试以可靠模式发送任何内容时,我无法跟踪消息,并且永远不会调用接收方侦听器。我正在尝试与两个玩家进行比赛,但我发现roomId对于他们来说是不同的(实际上,它的格式为XXX____YYY,而XXX字符串对于他们来说是相同的)。发送消息的代码如下:

private final RealTimeMultiplayerClient.ReliableMessageSentCallback mySentListener = new RealTimeMultiplayerClient.ReliableMessageSentCallback() {
    @Override
    public void onRealTimeMessageSent(int statusCode, int tokenId, String recipientParticipantId) {
        Log.d(TAG, "RealTime message sent");
        Log.d(TAG, "  statusCode: " + statusCode);
        Log.d(TAG, "  tokenId: " + tokenId);
        Log.d(TAG, "  recipientParticipantId: " + recipientParticipantId);
    }
};

public void sendReliable(final String playerId) {
    final Task<Integer> sendTask = GoogleRoom.getInstance().getRealTimeMultiplayerClient()
        .sendReliableMessage(buffer, GoogleRoom.mRoomId, playerId, mySentListener);
    sendTask.addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            Log.d(TAG, "Failure " + e);
        }
    });
    sendTask.addOnCompleteListener(new OnCompleteListener<Integer>() {
        @Override
        public void onComplete(@NonNull Task<Integer> task) {
            Log.d(TAG, "Completed");
        }
    });
    sendTask.addOnCanceledListener(new OnCanceledListener() {
           @Override
           public void onCanceled() {
               Log.d(TAG, "Canceled");
           }
    });
}

奇怪的是没有调用监听器。有什么建议吗?

0 个答案:

没有答案