[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Achievements 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/achievements).\n\nThis guide shows you how to use the achievements APIs in an Android application\nto unlock and display achievements in your game. The APIs can be found\nin the [`com.google.android.gms.games`](https://developers.google.com/android/reference/com/google/android/gms/games/package-summary)\nand [`com.google.android.gms.games.achievements`](https://developers.google.com/android/reference/com/google/android/gms/games/achievement/package-summary) packages.\n\nBefore you begin\n----------------\n\nIf you haven't already done so, you might find it helpful to review the\n[achievements game concepts](/games/pgs/achievements).\n\nBefore you start to code using the achievements API:\n\n- Follow the instructions for installing and setting up your app to use Google Play Games Services in the [Set Up Google Play services SDK](https://developers.google.com/android/guides/setup) guide.\n- Define the achievements that you want your game to unlock or display, by following the instructions in the [Google Play Console guide](/games/pgs/achievements#create_an_achievement).\n- Download and review the achievements code samples in the [Android samples page](https://github.com/playgameservices/android-basic-samples).\n- Familiarize yourself with the recommendations described in [Quality Checklist](/games/pgs/v1/quality).\n\nGet an achievements client\n--------------------------\n\nTo start using the achievements API, your game must first obtain an\n[`AchievementsClient`](https://developers.google.com/android/games_v1/reference/com/google/android/gms/games/AchievementsClient) object. You can do this by calling the\n[`Games.getAchievementClient()`](https://developers.google.com/android/games_v1/reference/com/google/android/gms/games/Games#public-static-achievementsclient-getachievementsclient-context-context,-googlesigninaccount-account) method and passing in the activity and the\n[`GoogleSignInAccount`](https://developers.google.com//android/reference/com/google/android/gms/auth/api/signin/GoogleSignInAccount) for the current player. To learn how to retrieve the\nplayer account information, see [Sign-in in Android Games](/games/pgs/v1/android/signin).\n| **Note:** The [`AchievementsClient`](https://developers.google.com/android/games_v1/reference/com/google/android/gms/games/AchievementsClient) 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\nUnlock achievements\n-------------------\n\nTo unlock an achievement, call the [`AchievementsClient.unlock()`](https://developers.google.com/android/games_v1/reference/com/google/android/gms/games/AchievementsClient.html#unlock(java.lang.String)) method and\npass in the achievement ID.\n\nThe following code snippet shows how your app can unlock achievements: \n\n```scdoc\nGames.getAchievementsClient(this, GoogleSignIn.getLastSignedInAccount(this))\n .unlock(getString(R.string.my_achievement_id));\n```\n\nIf the achievement is of the *incremental* type (that is, several steps are required to\nunlock it), call [`AchievementsClient.increment()`](https://developers.google.com/android/games_v1/reference/com/google/android/gms/games/AchievementsClient.html#increment(java.lang.String,%20int)) instead.\n\nThe following code snippet shows how your app can increment the player's achievement: \n\n```scdoc\nGames.getAchievementsClient(this, GoogleSignIn.getLastSignedInAccount(this))\n .increment(getString(R.string.my_achievement_id), 1);\n```\n\nYou do not need to write additional code to unlock the achievement; Google Play Games Services\nautomatically unlocks the achievement once it reaches its required number of steps.\n\nA good practice is to define the achievement IDs in the `strings.xml` file, so\nyour game can reference the achievements by resource ID. When making calls to update and load\nachievements, make sure to also follow these [best practices](/games/pgs/v1/quality) to\navoid exceeding your API quota.\n\nDisplay achievements\n--------------------\n\nTo show a player's achievements, call [`AchievementsClient.getAchievementsIntent()`](https://developers.google.com/android/games_v1/reference/com/google/android/gms/games/AchievementsClient.html#getAchievementsIntent())\nto get an [`Intent`](/reference/android/content/Intent) to create\nthe default achievements user interface. Your game can then bring up the UI by calling\n[`startActivityForResult`](/reference/android/app/Activity#startActivityForResult(android.content.Intent,%20int)).\n\nThe following code snippet shows how your app can display the default achievement user interface.\nIn the snippet, `RC_ACHIEVEMENT_UI` is an arbitrary integer that the game uses as the request code. \n\n```transact-sql\nprivate static final int RC_ACHIEVEMENT_UI = 9003;\n\nprivate void showAchievements() {\n Games.getAchievementsClient(this, GoogleSignIn.getLastSignedInAccount(this))\n .getAchievementsIntent()\n .addOnSuccessListener(new OnSuccessListener\u003cIntent\u003e() {\n @Override\n public void onSuccess(Intent intent) {\n startActivityForResult(intent, RC_ACHIEVEMENT_UI);\n }\n });\n}\n```\n\nAn example of the default achievements UI is shown below."]]