با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
پس از منسوخ شدن Google Sign-In API، ما بازیها v1 SDK را در سال 2026 حذف میکنیم. پس از فوریه 2025، نمیتوانید عناوینی را که به تازگی با بازیهای v1 SDK ادغام شدهاند، در Google Play منتشر کنید. توصیه می کنیم به جای آن از بازی ها v2 SDK استفاده کنید. در حالی که عناوین موجود با ادغام های قبلی نسخه 1 برای چند سال به کار خود ادامه می دهند، شما تشویق می شوید که از ژوئن 2025 به نسخه 2 مهاجرت کنید . این راهنما برای استفاده از Play Games Services v1 SDK است. برای اطلاعات در مورد آخرین نسخه SDK، به مستندات v2 مراجعه کنید.
این راهنما به شما نشان میدهد که چگونه دادههای گیمپلی بازیکنان را برای تجزیه و تحلیل بازی با استفاده از APIهای رویدادهای ارائهشده توسط خدمات بازیهای Google Play جمعآوری کنید. APIها را میتوانید در com.google.android.gms.games.event و com.google.android.gms.games پیدا کنید.
میتوانید کدی را به بازی خود اضافه کنید تا هر زمان که رویداد مورد علاقه بازی شما رخ میدهد، خدمات بازیهای Google Play را مطلع کنید.
برای ارسال بهروزرسانی رویداد، EventsClient.increment() را با مقدار eventId و یک عدد صحیح incrementAmount که مساوی یا بزرگتر از 0 است فراخوانی کنید.
eventId زمانی که برای اولین بار رویداد را در کنسول Google Play تعریف میکنید توسط سرویسهای بازیهای Google Play تولید میشود و برای شناسایی منحصربهفرد این رویداد در بازی شما استفاده میشود.
می توانید از ورودی incrementAmount برای مشخص کردن پیشرفت کمی بازیکن در جهت تکمیل اهداف خاص بازی استفاده کنید. برای مثال، اگر رویدادی که بازی شما میخواهد ردیابی کند «شکست دادن 500 هیولا با چشم اشکال» باشد، مقدار incrementAmount میتواند تعداد هیولایی باشد که بازیکن در یک نبرد کشته است.
در اینجا مثالی از نحوه ارسال یک رویداد با مقدار افزایشی 1 آورده شده است:
public void submitEvent(String eventId) {
Games.getEventsClient(this, GoogleSignIn.getLastSignedInAccount(this))
.increment(eventId, 1);
}
رویدادها را بازیابی کنید
با فراخوانی EventsClient.load() می توانید تمام داده های رویدادهای ذخیره شده در سرورهای Google را برای بازی خود بازیابی کنید. در فراخوانی روش، یک مقدار بولی ارسال کنید تا مشخص شود آیا خدمات بازیهای Google Play باید دادههای ذخیرهشده محلی را در دستگاه کاربر پاک کند یا خیر.
برای بازیابی دادههای رویدادهای خاصی که در کنسول Google Play تعریف کردهاید، با EventsClient.loadByIds() تماس بگیرید و آرایهای از شناسههای رویداد را در پارامترهای ورودی ارسال کنید.
قطعه زیر نشان میدهد که چگونه میتوانید از خدمات بازیهای Google Play برای لیست همه رویدادهای بازی خود پرس و جو کنید:
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Events in Android games\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/events).\n\nThis guide shows you how to collect player gameplay data for game analytics using the events APIs\nprovided by Google Play Games Services. The APIs can be found in the\n[`com.google.android.gms.games.event`](https://developers.google.com/android/reference/com/google/android/gms/games/event/package-summary)\nand [`com.google.android.gms.games`](https://developers.google.com/android/reference/com/google/android/gms/games/package-summary).\n\nBefore you begin\n----------------\n\nIf you haven't already done so, you might find it helpful to review the\n[events game concepts](/games/pgs/events).\n\nBefore you start to code using the events APIs:\n\n- Define the events for your game in the [Google Play Console](https://play.google.com/apps/publish/).\n- Follow the [sign-in checklist recommendations](/games/pgs/v1/quality#sign-in).\n\nGet the events client\n---------------------\n\nTo start using the events APIs, your game must first obtain an\n[`EventsClient`](https://developers.google.com/android/reference/com/google/android/gms/games/EventsClient) object. You can do this by calling the\n[`Games.getEventsClient()`](https://developers.google.com/android/reference/com/google/android/gms/games/Games.html#getEventsClient(android.app.Activity,%20com.google.android.gms.auth.api.signin.GoogleSignInAccount)) method and passing in the\nactivity and the [`GoogleSignInAccount`](https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInAccount) for the current player. To learn how to\nretrieve the player account information, see\n[Sign-in in Android Games](/games/pgs/v1/android/signin).\n| **Note:** The [`EventsClient`](https://developers.google.com/android/reference/com/google/android/gms/games/EventsClient) class makes use of the Google Play services [`Task`](https://developers.google.com/android/reference/com/google/android/gms/tasks/Task) class to return results asynchronously. To learn more about using tasks to manage threaded work, see the [Tasks API developer guide](https://developers.google.com/android/guides/tasks).\n\nSubmit events\n-------------\n\nYou can add code in your game to notify Google Play Games Services whenever an\nevent of interest to your game occurs.\n\nTo send an event update, call [`EventsClient.increment()`](https://developers.google.com/android/reference/com/google/android/gms/games/EventsClient.html#increment(java.lang.String,%20int)) with the `eventId` value and an\ninteger `incrementAmount` that is equal to or greater than 0.\n\n- The `eventId` is generated by Google Play Games Services when you first define the event in the Google Play Console and is used to uniquely identify this event in your game.\n- You can use the `incrementAmount` input to specify the player's quantitative progress towards completing some game-specific goal. For example, if the event your game wants to track is *'Defeat 500 bug-eyed monsters'* , the `incrementAmount` value can be the number of monsters that the player killed in a single battle.\n\nHere's an example of how to submit an event with an increment amount of 1: \n\n```text\npublic void submitEvent(String eventId) {\n Games.getEventsClient(this, GoogleSignIn.getLastSignedInAccount(this))\n .increment(eventId, 1);\n}\n```\n\nRetrieve events\n---------------\n\nYou can retrieve all events data stored in Google's servers for your game, by\ncalling [`EventsClient.load()`](https://developers.google.com/android/reference/com/google/android/gms/games/EventsClient.html#load(boolean)). In the\nmethod call, pass in a boolean value to indicate if Google Play Games Services should clear the locally\ncached data on the user's device.\n\nTo retrieve data for specific events that you defined in the Google Play Console, call\n[`EventsClient.loadByIds()`](https://developers.google.com/android/reference/com/google/android/gms/games/EventsClient.html#loadByIds(boolean,%20java.lang.String...)) and pass in an array of event IDs in the input parameters.\n\nThe following snippet shows how you can query Google Play Games Services for the\nlist of all events for your game: \n\n```gdscript\npublic void loadEvents() {\n Games.getEventsClient(this, GoogleSignIn.getLastSignedInAccount(this))\n .load(true)\n .addOnCompleteListener(new OnCompleteListener\u003cAnnotatedData\u003cEventBuffer\u003e\u003e() {\n @Override\n public void onComplete(@NonNull Task\u003cAnnotatedData\u003cEventBuffer\u003e\u003e task) {\n if (task.isSuccessful()) {\n // Process all the events.\n for (Event event : task.getResult().get()) {\n Log.d(TAG, \"loaded event \" + event.getName());\n }\n } else {\n // Handle Error\n Exception exception = task.getException();\n int statusCode = CommonStatusCodes.DEVELOPER_ERROR;\n if (exception instanceof ApiException) {\n ApiException apiException = (ApiException) exception;\n statusCode = apiException.getStatusCode();\n }\n showError(statusCode);\n }\n }\n });\n}\n```"]]