Java Code Examples for com.google.android.gms.games.Games#getPlayersClient()
The following examples show how to use
com.google.android.gms.games.Games#getPlayersClient() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlayGamesPlugin.java From play_games with MIT License | 6 votes |
private void handleSuccess(GoogleSignInAccount acc) { currentAccount = acc; PlayersClient playersClient = Games.getPlayersClient(registrar.activity(), currentAccount); playersClient.getCurrentPlayer().addOnSuccessListener(new OnSuccessListener<Player>() { @Override public void onSuccess(Player player) { Map<String, Object> successMap = new HashMap<>(); successMap.put("type", "SUCCESS"); successMap.put("id", player.getPlayerId()); successMap.put("email", currentAccount.getEmail()); successMap.put("displayName", player.getDisplayName()); successMap.put("hiResImageUri", player.getHiResImageUri().toString()); successMap.put("iconImageUri", player.getIconImageUri().toString()); result(successMap); } }).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(Exception e) { error("ERROR_FETCH_PLAYER_PROFILE", e); } }); }
Example 2
Source File: Request.java From play_games with MIT License | 5 votes |
public void getHiResImage() { PlayersClient playersClient = Games.getPlayersClient(registrar.activity(), currentAccount); playersClient.getCurrentPlayer().addOnSuccessListener(new OnSuccessListener<Player>() { @Override public void onSuccess(Player player) { readImage(player.getHiResImageUri()); } }); }
Example 3
Source File: Request.java From play_games with MIT License | 5 votes |
public void getIconImage() { PlayersClient playersClient = Games.getPlayersClient(registrar.activity(), currentAccount); playersClient.getCurrentPlayer().addOnSuccessListener(new OnSuccessListener<Player>() { @Override public void onSuccess(Player player) { readImage(player.getHiResImageUri()); } }); }
Example 4
Source File: MainActivity.java From android-basic-samples with Apache License 2.0 | 4 votes |
private void onConnected(GoogleSignInAccount googleSignInAccount) { Log.d(TAG, "onConnected(): connected to Google APIs"); mAchievementsClient = Games.getAchievementsClient(this, googleSignInAccount); mLeaderboardsClient = Games.getLeaderboardsClient(this, googleSignInAccount); mEventsClient = Games.getEventsClient(this, googleSignInAccount); mPlayersClient = Games.getPlayersClient(this, googleSignInAccount); // Show sign-out button on main menu mMainMenuFragment.setShowSignInButton(false); // Show "you are signed in" message on win screen, with no sign in button. mWinFragment.setShowSignInButton(false); // Set the greeting appropriately on main menu mPlayersClient.getCurrentPlayer() .addOnCompleteListener(new OnCompleteListener<Player>() { @Override public void onComplete(@NonNull Task<Player> task) { String displayName; if (task.isSuccessful()) { displayName = task.getResult().getDisplayName(); } else { Exception e = task.getException(); handleException(e, getString(R.string.players_exception)); displayName = "???"; } mMainMenuFragment.setGreeting("Hello, " + displayName); } }); // if we have accomplishments to push, push them if (!mOutbox.isEmpty()) { pushAccomplishments(); Toast.makeText(this, getString(R.string.your_progress_will_be_uploaded), Toast.LENGTH_LONG).show(); } loadAndPrintEvents(); }
Example 5
Source File: MainActivity.java From android-basic-samples with Apache License 2.0 | 4 votes |
private void onConnected(GoogleSignInAccount googleSignInAccount) { Log.d(TAG, "onConnected(): connected to Google APIs"); if (mSignedInAccount != googleSignInAccount) { mSignedInAccount = googleSignInAccount; // update the clients mRealTimeMultiplayerClient = Games.getRealTimeMultiplayerClient(this, googleSignInAccount); mInvitationsClient = Games.getInvitationsClient(MainActivity.this, googleSignInAccount); // get the playerId from the PlayersClient PlayersClient playersClient = Games.getPlayersClient(this, googleSignInAccount); playersClient.getCurrentPlayer() .addOnSuccessListener(new OnSuccessListener<Player>() { @Override public void onSuccess(Player player) { mPlayerId = player.getPlayerId(); switchToMainScreen(); } }) .addOnFailureListener(createFailureListener("There was a problem getting the player id!")); } // register listener so we are notified if we receive an invitation to play // while we are in the game mInvitationsClient.registerInvitationCallback(mInvitationCallback); // get the invitation from the connection hint // Retrieve the TurnBasedMatch from the connectionHint GamesClient gamesClient = Games.getGamesClient(MainActivity.this, googleSignInAccount); gamesClient.getActivationHint() .addOnSuccessListener(new OnSuccessListener<Bundle>() { @Override public void onSuccess(Bundle hint) { if (hint != null) { Invitation invitation = hint.getParcelable(Multiplayer.EXTRA_INVITATION); if (invitation != null && invitation.getInvitationId() != null) { // retrieve and cache the invitation ID Log.d(TAG, "onConnected: connection hint has a room invite!"); acceptInviteToRoom(invitation.getInvitationId()); } } } }) .addOnFailureListener(createFailureListener("There was a problem getting the activation hint!")); }