সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
অ্যান্ড্রয়েড স্টুডিও প্রোজেক্টে ফ্রেন্ডস এপিআই কীভাবে ব্যবহার করবেন এই গাইডটি বর্ণনা করে।
বন্ধুদের লোড
আপনি বর্তমান ব্যবহারকারীর সাথে বন্ধুত্বপূর্ণ খেলোয়াড়দের একটি তালিকা (গেমে) পুনরুদ্ধার করতে এবং প্রদর্শন করতে পারেন। একজন ব্যবহারকারী হিসাবে, বন্ধুদের তালিকায় কোন গেমগুলির অ্যাক্সেস রয়েছে তা নিয়ন্ত্রণ করা সম্ভব। আপনি যখন বন্ধুদের তালিকা পুনরুদ্ধার করবেন, আপনাকে অবশ্যই সেই ক্ষেত্রে পরিচালনা করতে হবে যেখানে অনুমতির প্রয়োজন হয়৷ অ্যাক্সেসের অনুরোধ করার জন্য এবং পরবর্তীতে বন্ধুদের তালিকা ব্যবহার করে সহজবোধ্য কাজ করার জন্য এগুলি সবই API এ এনক্যাপসুলেট করা হয়েছে। বন্ধুদের তালিকা লোড করতে, এই পদক্ষেপগুলি অনুসরণ করুন:
যদি কলটি সফল হয় (ব্যবহারকারী ইতিমধ্যেই বন্ধুদের তালিকায় অ্যাক্সেস মঞ্জুর করেছে), Google Play গেম পরিষেবাগুলি একটি টীকাযুক্ত PlayerBuffer প্রদান করে যা ব্যবহারকারীর বন্ধুদের প্রতিনিধিত্ব করে।
যদি প্লেয়ারকে বন্ধুদের তালিকায় অ্যাক্সেস দেওয়ার প্রয়োজন হয়, তাহলে একটি FriendsResolutionRequiredException এর সাথে কলটি ব্যর্থ হয়। কোন ডায়ালগ এখনও দেখানো হয় না.
এই ব্যতিক্রমটিতে একটি Intent রয়েছে যা প্লেয়ারের সম্মতি চাওয়ার জন্য একটি ডায়ালগ ট্রিগার করে। আপনি একটি সম্মতি ডায়ালগ খুলতে অবিলম্বে এই Intent চালু করতে পারেন। আপনি শুধুমাত্র একবার এই Intent ব্যবহার করতে পারেন.
যদি Intent কার্যকলাপের ফলাফল হয় Activity.RESULT_OK 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.PlayGames.getPlayersClient(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.}}}
অন্য খেলোয়াড়ের প্রোফাইল দেখুন
আপনি আপনার গেমের মধ্যে থেকে অন্য প্লেয়ারের প্লে গেমস প্রোফাইলের একটি দৃশ্য প্রদর্শন করতে পারেন। এই ভিউ খেলোয়াড়দের দেখার জন্য বন্ধুদের আমন্ত্রণ পাঠাতে এবং গ্রহণ করতে দেয়। এই দৃশ্যের জন্য বন্ধুদের তালিকায় প্রবেশের প্রয়োজন নেই। উপরন্তু, যদি আপনার গেমের প্লে গেম গেমার আইডি থেকে আলাদা প্লেয়ারের নামের নিজস্ব ধারণা থাকে, তাহলে আপনি এগুলিকে প্রোফাইল ভিউতে পাস করতে পারেন যাতে অতিরিক্ত প্রসঙ্গের জন্য যেকোনো বন্ধুর আমন্ত্রণে অন্তর্ভুক্ত করা যায়।
অন্য খেলোয়াড়ের প্রোফাইল দেখাতে, এই পদক্ষেপগুলি অনুসরণ করুন:
কলটি সফল হলে, Google Play Games Services একটি ইন্টেন্ট প্রদান করে যা একটি স্ক্রীন প্রদর্শন করবে যেখানে ব্যবহারকারী অন্য খেলোয়াড়ের প্রোফাইলের সাথে নিজেদের তুলনা করতে পারবে।
একটি কার্যকলাপ শুরু করতে পূর্ববর্তী ধাপ থেকে Intent ব্যবহার করুন.
// Retrieve and launch an Intent to show a player profile within the game.PlayGames.getPlayersClient(this).getCompareProfileIntent(otherPlayerId).addOnSuccessListener(newOnSuccessListener<Intent>(){@OverridepublicvoidonSuccess(Intentintent){startActivityForResult(intent,RC_SHOW_PROFILE);// ...}});
খেলোয়াড়দের জন্য গেমটির নিজস্ব নাম থাকলে, এগুলি API কলে যোগ করা যেতে পারে। এটি প্লে গেমগুলিকে সেই খেলোয়াড়দের ডাকনাম সেট করতে সক্ষম করে যারা আপনার গেমের মধ্যে থেকে "<game-specific-name> থেকে <your-game-name>" থেকে <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.PlayGames.PlayersClient(this).getCompareProfileIntentWithAlternativeNameHints(otherPlayerId,otherPlayerInGameName,currentPlayerInGameName).addOnSuccessListener(newOnSuccessListener<Intent>(){@OverridepublicvoidonSuccess(Intentintent){startActivityForResult(intent,RC_SHOW_PROFILE);// ...}});
এই পৃষ্ঠার কন্টেন্ট ও কোডের নমুনাগুলি Content License-এ বর্ণিত লাইসেন্সের অধীনস্থ। Java এবং OpenJDK হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-07-29 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-29 UTC-তে শেষবার আপডেট করা হয়েছে।"],[],[],null,["# Friends in Android games\n\n| **Note:** This guide is for the Play Games Services v2 SDK. For information on the previous version of this SDK, see the [Play Games Services v1\n| documentation](/games/pgs/v1/android/friends).\n\nThis guide describes how to use the [Friends](/games/pgs/friends) APIs in\nAndroid Studio projects.\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 load 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 PlayGames.getPlayersClient(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 PlayGames.getPlayersClient(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 PlayGames.PlayersClient(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 }});"]]