Following the deprecation of the[Google Sign-In](https://android-developers.googleblog.com/2024/09/streamlining-android-authentication-credential-manager-replaces-legacy-apis.html)API, we are removing the games v1 SDK in 2026. After February 2025, you will be unable to publish titles that are newly integrated with games v1 SDK, on Google Play. We recommend that you use the games v2 SDK instead.  
While existing titles with the previous games v1 integrations continue to function for a couple of years, you are encouraged to[migrate to v2](https://developer.android.com/games/pgs/android/migrate-to-v2)starting June 2025.  
This guide is for using the Play Games Services v1 SDK. For information on the latest SDK version, see the[v2 documentation](https://developer.android.com/games/pgs/android/friends).

Use the steps in this guide to implement the Friends APIs in your Java game code.

## Load friends

You can retrieve and display (in the game) a list of players who are friends with the current user. As a user, it is possible to control which games have access to the friends list. When you retrieve the friends list, you must handle the case where permission is required. This is all encapsulated in the API to make requesting access and subsequently using the friends list a straightforward task. To load the friends list, follow these steps:

1. Call the[`PlayersClient.loadFriends()`](https://developers.google.com/android/reference/com/google/android/gms/games/PlayersClient#loadFriends(int,%20boolean))method, which is an asynchronous call returning a[`Task`](https://developers.google.com/android/reference/com/google/android/gms/tasks/Task)object.
2. If the call is successful (the user already granted access to the friends list), Google Play Games Services returns an annotated[`PlayerBuffer`](https://developers.google.com/android/reference/com/google/android/gms/games/PlayerBuffer)that represents the user's friends.
3. If the player needs to grant access to the friends list, the call fails with a[`FriendsResolutionRequiredException`](https://developers.google.com/android/reference/com/google/android/gms/games/FriendsResolutionRequiredException). No dialogs are shown yet.

   1. This exception contains an`Intent`that triggers a dialog to ask the player for consent. You can launch this`Intent`immediately to open a consent dialog. You can only use this`Intent`once.
   2. If the result of the`Intent`'s activity is`Activity.RESULT_OK`, then consent was granted. Call`loadFriends()`again to return the friends list. If the result is`Activity.RESULT_CANCELLED`, the user did not consent and`loadFriends()`will continue to return`FriendsResolutionRequiredException`.

      | **Note:** If you call`loadFriends()`from your server and determine that you need to request consent, you need to call`loadFriends()`again from your game client. This second call won't succeed, but it will provide you the`Intent`required to show the consent dialog.

The following code shows how to implement loading the friends list:  

    // Attempt loading friends.
    // Register a success listener to handle the successfully loaded friends list.
    // Register a failure listener to handle asking for permission to access the list.
    Games.getPlayersClient(this, GoogleSignIn.getLastSignedInAccount(this))
        .loadFriends(PAGE_SIZE, /* forceReload= */ false)
        .addOnSuccessListener(
            new OnSuccessListener<AnnotatedData<PlayerBuffer>>() {
                @Override
                public void onSuccess(AnnotatedData<PlayerBuffer>  data) {
              PlayerBuffer playerBuffer = data.get();
              // ...
            })

        .addOnFailureListener(
            exception -> {
          if (exception instanceof FriendsResolutionRequiredException) {
            PendingIntent pendingIntent =
                ((FriendsResolutionRequiredException) task.getException())
                .getResolution();
            parentActivity.startIntentSenderForResult(
                pendingIntent.getIntentSender(),
                /* requestCode */ SHOW_SHARING_FRIENDS_CONSENT,
                /* fillInIntent */ null,
                /* flagsMask */ 0,
                /* flagsValues */ 0,
                /* extraFlags */ 0,
                /* options */ null);
         }
       });
     return;
    }

The following code shows how to handle the result from the request for consent:  

    /** Handle the activity result from the request for consent. */
    @Override
    public void onActivityResult(int requestCode, int result, Intent data) {
      if (requestCode == SHOW_SHARING_FRIENDS_CONSENT) {
        if (result == Activity.RESULT_OK) {
          // We got consent from the user to access their friends. Retry loading the friends
          callLoadFriends();
        } else {
          // User did not grant consent.
        }
      }
    }

## View another player's profile

You can display a view of another player's Play Games profile from within your game. This view allows players to send and accept friend invitations for the player being viewed. This view does not require access to the friends list. Additionally, if your game has its own concept of player names separate from Play Games Gamer IDs, you can pass these along to the profile view so that they can be included in any friend invitations for additional context.

To show another player's profile, follow these steps:

1. Call the[`PlayersClient.getCompareProfileIntent()`](https://developers.google.com/android/reference/com/google/android/gms/games/PlayersClient)method, which is an asynchronous call returning a[`Task`](https://developers.google.com/android/reference/com/google/android/gms/tasks/Task)object.
2. If the call is successful, Google Play Games Services returns an Intent that will display a screen where the user can compare themselves against another player's profile.
3. Use the`Intent`from the previous step to start an activity.

    // Retrieve and launch an Intent to show a player profile within the game.
    Games.getPlayersClient(this, GoogleSignIn.getLastSignedInAccount(this))
        .getCompareProfileIntent(otherPlayerId)
        .addOnSuccessListener(new OnSuccessListener<Intent>() {
            @Override
            public void onSuccess(Intent  intent) {
              startActivityForResult(intent, RC_SHOW_PROFILE);
              // ...
            }});

If the game has its own name for players, these can be added to the API call. This enables Play Games to set the nickname of players who send friend invitations from within your game to "\<game-specific-name\> from \<your-game-name\>" (Play Games automatically appends "from \<your-game-name\>"):  

    // Show a player profile within the game, with additional hints containing the
    // game-specific names for both players.
    // - otherPlayerId is the Play Games playerId of the player to view.
    // - otherPlayerInGameName is the game-specific name of the player being viewed.
    // - currentPlayerInGameName is the game-specific name of the player who is signed
    //   in. Hence if the player sends an invitation to the profile they are viewing,
    //   their game-specific name can be included.
    Games.PlayersClient(this, GoogleSignIn.getLastSignedInAccount(this))
        .getCompareProfileIntentWithAlternativeNameHints(otherPlayerId, otherPlayerInGameName, currentPlayerInGameName)
        .addOnSuccessListener(new OnSuccessListener<Intent>() {
            @Override
            public void onSuccess(Intent  intent) {
              startActivityForResult(intent, RC_SHOW_PROFILE);
              // ...
            }});