Google 로그인 API가 지원 중단됨에 따라 2026년에 게임 v1 SDK가 삭제됩니다. 2025년 2월 이후에는 게임 v1 SDK와 새로 통합된 타이틀을 Google Play에 게시할 수 없습니다. 대신 games v2 SDK를 사용하는 것이 좋습니다.
이전 게임 v1 통합이 적용된 기존 타이틀은 몇 년 동안 계속 작동하지만 2025년 6월부터는 v2로 이전하는 것이 좋습니다.
이 가이드는 Play 게임즈 서비스 v1 SDK 사용에 관한 가이드입니다. 최신 SDK 버전에 관한 자세한 내용은 v2 문서를 참고하세요.
이 가이드의 단계에 따라 Java 게임 코드에서 Friends API를 구현합니다.
친구 로드
현재 사용자와 친구인 플레이어 목록을 게임에서 가져와서 표시할 수 있습니다. 사용자는 친구 목록에 액세스할 수 있는 게임을 제어할 수 있습니다. 친구 목록을 가져올 때는 권한이 필요한 경우를 처리해야 합니다. 이러한 작업은 모두 API에 캡슐화되므로 액세스 권한을 요청하고 이후에 친구 목록을 사용하는 작업이 간단해집니다. 친구 목록을 로드하려면 다음 단계를 따르세요.
이 예외에는 플레이어에게 동의를 요청하는 대화상자를 트리거하는 Intent가 포함됩니다. 이 Intent를 즉시 실행하여
동의 대화상자를 열 수 있습니다. 이 Intent는 한 번만 사용할 수 있습니다.
Intent 활동의 결과가 Activity.RESULT_OK인 경우
동의가 부여된 것입니다. loadFriends()를 다시 호출하여 친구 목록을 반환합니다. 결과가 Activity.RESULT_CANCELLED이면 사용자가 동의하지 않은 것이며 loadFriends()는 계속 FriendsResolutionRequiredException을 반환합니다.
다음 코드는 친구 목록 로드를 구현하는 방법을 보여줍니다.
// 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(newOnSuccessListener<AnnotatedData<PlayerBuffer>>(){@OverridepublicvoidonSuccess(AnnotatedData<PlayerBuffer>data){PlayerBufferplayerBuffer=data.get();// ...}).addOnFailureListener(exception->{if(exceptioninstanceofFriendsResolutionRequiredException){PendingIntentpendingIntent=((FriendsResolutionRequiredException)task.getException()).getResolution();parentActivity.startIntentSenderForResult(pendingIntent.getIntentSender(),/* requestCode */SHOW_SHARING_FRIENDS_CONSENT,/* fillInIntent */null,/* flagsMask */0,/* flagsValues */0,/* extraFlags */0,/* options */null);}});return;}
다음 코드는 동의 요청 결과를 처리하는 방법을 보여줍니다.
/** Handle the activity result from the request for consent. */@OverridepublicvoidonActivityResult(intrequestCode,intresult,Intentdata){if(requestCode==SHOW_SHARING_FRIENDS_CONSENT){if(result==Activity.RESULT_OK){// We got consent from the user to access their friends. Retry loading the friendscallLoadFriends();}else{// User did not grant consent.}}}
다른 플레이어의 프로필 보기
게임 내에서 다른 플레이어의 Play 게임즈 프로필 뷰를 표시할 수 있습니다. 이 뷰를 통해 플레이어는 보고 있는 플레이어의 친구 초대를
보내고 수락할 수 있습니다. 이 뷰에는 친구 목록 액세스 권한이 필요하지 않습니다. 또한 게임에 Play 게임즈 게이머 ID와는 별개로 자체 플레이어 이름 개념이 있으면 추가 컨텍스트를 위해 친구 초대에 포함할 수 있도록 프로필 뷰에 이를 전달할 수 있습니다.
호출이 성공하면 Google Play 게임즈 서비스는 사용자가 다른 플레이어의 프로필과 비교할 수 있는 화면을 표시하는 인텐트를 반환합니다.
이전 단계의 Intent를 사용하여 활동을 시작합니다.
// Retrieve and launch an Intent to show a player profile within the game.Games.getPlayersClient(this,GoogleSignIn.getLastSignedInAccount(this)).getCompareProfileIntent(otherPlayerId).addOnSuccessListener(newOnSuccessListener<Intent>(){@OverridepublicvoidonSuccess(Intentintent){startActivityForResult(intent,RC_SHOW_PROFILE);// ...}});
게임에 플레이어의 고유 이름이 있는 경우 API 호출에 추가할 수 있습니다.
이를 통해 Play 게임즈에서는 게임 내에서 친구 초대를 보내는 플레이어의 닉네임을 '<your-game-name>'에서 '<game-specific-name>'으로 설정할 수 있습니다. Play 게임즈는 자동으로 '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(newOnSuccessListener<Intent>(){@OverridepublicvoidonSuccess(Intentintent){startActivityForResult(intent,RC_SHOW_PROFILE);// ...}});
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Integrate the Friends APIs (Java)\n\nFollowing the deprecation of the\n[Google Sign-In](https://android-developers.googleblog.com/2024/09/streamlining-android-authentication-credential-manager-replaces-legacy-apis.html)\nAPI, we are removing the games v1 SDK in 2026. After February 2025, you will be unable to publish\ntitles that are newly integrated with games v1 SDK, on Google Play. We recommend that you use the\ngames v2 SDK instead. \n\nWhile existing titles with the previous games v1 integrations continue to function for a\ncouple of years, you are encouraged to\n[migrate to v2](/games/pgs/android/migrate-to-v2)\nstarting June 2025. \n\nThis guide is for using the Play Games Services v1 SDK. For information\non the latest SDK version, see the\n[v2 documentation](/games/pgs/android/friends).\n\nUse the steps in this guide to implement the Friends APIs in your Java game code.\n\nLoad friends\n------------\n\nYou can retrieve and display (in the game) a list of players who are friends\nwith the current user. As a user, it is possible to control which games have\naccess to the friends list. When you retrieve the friends list, you must handle\nthe case where permission is required. This is all encapsulated in the API to\nmake requesting access and subsequently using the friends list a straightforward\ntask. To load the friends list, follow these steps:\n\n1. 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.\n2. 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.\n3. If the player needs to grant access to the friends list, the call fails with\n a\n [`FriendsResolutionRequiredException`](https://developers.google.com/android/reference/com/google/android/gms/games/FriendsResolutionRequiredException).\n No dialogs are shown yet.\n\n 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.\n 2. If the result of the `Intent`'s activity is `Activity.RESULT_OK`, then\n consent was granted. Call `loadFriends()` again to return the friends\n list. If the result is `Activity.RESULT_CANCELLED`, the user did\n not consent and `loadFriends()` will continue to return\n `FriendsResolutionRequiredException`.\n\n | **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.\n\nThe following code shows how to implement loading the friends list: \n\n // Attempt loading friends.\n // Register a success listener to handle the successfully loaded friends list.\n // Register a failure listener to handle asking for permission to access the list.\n Games.getPlayersClient(this, GoogleSignIn.getLastSignedInAccount(this))\n .loadFriends(PAGE_SIZE, /* forceReload= */ false)\n .addOnSuccessListener(\n new OnSuccessListener\u003cAnnotatedData\u003cPlayerBuffer\u003e\u003e() {\n @Override\n public void onSuccess(AnnotatedData\u003cPlayerBuffer\u003e data) {\n PlayerBuffer playerBuffer = data.get();\n // ...\n })\n\n .addOnFailureListener(\n exception -\u003e {\n if (exception instanceof FriendsResolutionRequiredException) {\n PendingIntent pendingIntent =\n ((FriendsResolutionRequiredException) task.getException())\n .getResolution();\n parentActivity.startIntentSenderForResult(\n pendingIntent.getIntentSender(),\n /* requestCode */ SHOW_SHARING_FRIENDS_CONSENT,\n /* fillInIntent */ null,\n /* flagsMask */ 0,\n /* flagsValues */ 0,\n /* extraFlags */ 0,\n /* options */ null);\n }\n });\n return;\n }\n\nThe following code shows how to handle the result from the request for consent: \n\n /** Handle the activity result from the request for consent. */\n @Override\n public void onActivityResult(int requestCode, int result, Intent data) {\n if (requestCode == SHOW_SHARING_FRIENDS_CONSENT) {\n if (result == Activity.RESULT_OK) {\n // We got consent from the user to access their friends. Retry loading the friends\n callLoadFriends();\n } else {\n // User did not grant consent.\n }\n }\n }\n\nView another player's profile\n-----------------------------\n\nYou can display a view of another player's Play Games profile from\nwithin your game. This view allows players to send and accept friend invitations\nfor the player being viewed. This view does not require access to the friends\nlist. Additionally, if your game has its own concept of player names separate\nfrom Play Games Gamer IDs, you can pass these along to the profile view\nso that they can be included in any friend invitations for additional context.\n\nTo show another player's profile, follow these steps:\n\n1. 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.\n2. 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.\n3. Use the `Intent` from the previous step to start an activity.\n\n // Retrieve and launch an Intent to show a player profile within the game.\n Games.getPlayersClient(this, GoogleSignIn.getLastSignedInAccount(this))\n .getCompareProfileIntent(otherPlayerId)\n .addOnSuccessListener(new OnSuccessListener\u003cIntent\u003e() {\n @Override\n public void onSuccess(Intent intent) {\n startActivityForResult(intent, RC_SHOW_PROFILE);\n // ...\n }});\n\nIf the game has its own name for players, these can be added to the API call.\nThis enables Play Games to set the nickname of players who send friend\ninvitations from within your game to \"\\\u003cgame-specific-name\\\u003e from\n\\\u003cyour-game-name\\\u003e\" (Play Games automatically appends \"from\n\\\u003cyour-game-name\\\u003e\"): \n\n // Show a player profile within the game, with additional hints containing the\n // game-specific names for both players.\n // - otherPlayerId is the Play Games playerId of the player to view.\n // - otherPlayerInGameName is the game-specific name of the player being viewed.\n // - currentPlayerInGameName is the game-specific name of the player who is signed\n // in. Hence if the player sends an invitation to the profile they are viewing,\n // their game-specific name can be included.\n Games.PlayersClient(this, GoogleSignIn.getLastSignedInAccount(this))\n .getCompareProfileIntentWithAlternativeNameHints(otherPlayerId, otherPlayerInGameName, currentPlayerInGameName)\n .addOnSuccessListener(new OnSuccessListener\u003cIntent\u003e() {\n @Override\n public void onSuccess(Intent intent) {\n startActivityForResult(intent, RC_SHOW_PROFILE);\n // ...\n }});"]]