Here are the examples of the java api class com.google.android.gms.games.multiplayer.Participant taken from open source projects.
1. RoomController#onRoomConnected()
Project: dice-heroes
File: RoomController.java
File: RoomController.java
@Override public void onRoomConnected(final int statusCode, final Room room) { Logger.log("room connected, status ok: " + (statusCode == GamesStatusCodes.STATUS_OK)); if (statusCode != GamesStatusCodes.STATUS_OK) { die(false, Config.thesaurus.localize("disconnect-game-services-error")); return; } RoomController.this.room = room; session.setVariant(room.getVariant()); String playerId = room.getParticipantId(Games.Players.getCurrentPlayerId(multiplayer.client)); for (Participant participant : room.getParticipants()) { if (participant.getStatus() != Participant.STATUS_JOINED) continue; if (participant.getParticipantId().equals(playerId)) { me = new MultiplayerParticipant(participant); } else { others.add(new MultiplayerParticipant(participant)); } } all.put(me.getId(), me); for (MultiplayerParticipant p : others) { all.put(p.getId(), p); } publicOthers = new ObjectSet<IParticipant>(others); publicAll = new ObjectMap<String, IParticipant>(all); multiplayer.updateInvites(); Logger.log(" - room: " + RoomController.this.toString(room)); }
2. MainActivity#broadcastScore()
Project: android-basic-samples
File: MainActivity.java
File: MainActivity.java
// Broadcast my score to everybody else. void broadcastScore(boolean finalScore) { if (!mMultiplayer) // playing single-player mode return; // First byte in message indicates whether it's a final score or not mMsgBuf[0] = (byte) (finalScore ? 'F' : 'U'); // Second byte is the score. mMsgBuf[1] = (byte) mScore; // Send to every other participant. for (Participant p : mParticipants) { if (p.getParticipantId().equals(mMyId)) continue; if (p.getStatus() != Participant.STATUS_JOINED) continue; if (finalScore) { // final score notification must be sent via reliable message Games.RealTimeMultiplayer.sendReliableMessage(mGoogleApiClient, null, mMsgBuf, mRoomId, p.getParticipantId()); } else { // it's an interim score notification, so we can use unreliable Games.RealTimeMultiplayer.sendUnreliableMessage(mGoogleApiClient, mMsgBuf, mRoomId, p.getParticipantId()); } } }