// Only call this for Android 12 and higher devicesif(Build.VERSION.SDK_INT>=Build.VERSION_CODES.S){// Get GameManager from SystemServiceGameManagergameManager=Context.getSystemService(GameManager.class);// Returns the selected GameModeintgameMode=gameManager.getGameMode();}
Kotlin
// Only call this for Android 12 and higher devicesif(Build.VERSION.SDK_INT>=Build.VERSION_CODES.S){// Get GameManager from SystemServicevalgameManager:GameManager? =context.getSystemService(Context.GAME_SERVICE)asGameManager?// Returns the selected GameModevalgameMode=gameManager?.gameMode}
[[["容易理解","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-26 (世界標準時間)。"],[],[],null,["# Game Mode API\n\nThe Game Mode API allows you to optimize your game for the best performance or\nlongest battery life when the user selects the corresponding game mode.\n\nAlternatively, you can submit requests for\n[Game Mode interventions](/games/optimize/adpf/gamemode/gamemode-interventions) to improve\nthe performance of games that are no longer being updated by developers.\n\nThe Game Mode API and interventions are available on:\n\n- Select [Android 12](/about/versions/12/get) devices\n- Devices running [Android 13](/about/versions/13/get) or higher\n\nEach game may implement the Game Mode API behavior, propose Game Mode\ninterventions settings to OEMs, or\n[opt out of Game Mode interventions](/games/optimize/adpf/gamemode/gamemode-interventions#opt-out_from_interventions).\n| **Warning:** OEMs may choose to implement Game Mode interventions without developer feedback.\n\nSetup\n-----\n\nTo use the Game Mode API in your game, do the following:\n\n1. Download and install the\n [Android 13 SDK](/about/versions/13/setup-sdk).\n\n2. In the [`AndroidManifest.xml`](/guide/topics/manifest/manifest-intro) file,\n declare your app as a game by setting the\n [`appCategory`](/reference/android/R.attr#appCategory) attribute in the\n [`\u003capplication\u003e`](/guide/topics/manifest/application-element) element:\n\n android:appCategory=\"game\"\n\n1. Query the current game mode by adding this to your main activity:\n\n### Java\n\n // Only call this for Android 12 and higher devices\n if ( Build.VERSION.SDK_INT \u003e= Build.VERSION_CODES.S ) {\n // Get GameManager from SystemService\n GameManager gameManager = Context.getSystemService(GameManager.class);\n\n // Returns the selected GameMode\n int gameMode = gameManager.getGameMode();\n }\n\n### Kotlin\n\n // Only call this for Android 12 and higher devices\n if (Build.VERSION.SDK_INT \u003e= Build.VERSION_CODES.S) {\n // Get GameManager from SystemService\n val gameManager: GameManager? = context.getSystemService(Context.GAME_SERVICE) as GameManager?\n\n // Returns the selected GameMode\n val gameMode = gameManager?.gameMode\n }\n\n| Supported game mode | Description |\n|---------------------|----------------------------------------------------------------------------------------------------------|\n| UNSUPPORTED | The game does not declare support for the Game Mode API and it does not support Game Mode interventions. |\n| STANDARD | The user has not selected a game mode or the user selected standard mode. |\n| PERFORMANCE | Provides the lowest latency frame rates in exchange for reduced battery life and fidelity. |\n| BATTERY | Provides the longest possible battery life in exchange for reduced fidelity or frame rates. |\n\n| **Important:** Battery Saver mode is game-specific and does not impact system level Android Battery Saver behavior.\n\n1. Add code to query the game mode state in the\n [`onResume`](/reference/android/app/Activity#onResume()) function:\n\n| **Important:** Your app must always query the `getGameMode()` method when resuming a paused process. See the diagram above for details.\n\n### Best Practices\n\nIf your game already supports multiple fidelity and frame rate\ntargets, you should identify the appropriate settings for performance and\nbattery saver modes:\n\n- To consistently achieve the maximum device frame rates: consider slight\n reductions in fidelity to achieve higher frame rates.\n\n- To improve battery life: consider choosing a lower display refresh rate (e.g.\n 30Hz or 60Hz) and [use frame pacing](/games/sdk/frame-pacing) to target the\n reduced rate.\n\nFor high-fidelity games such as first-person shooters, multiplayer online\nbattle arenas (MOBAs), and role-playing games (RPGs), you should focus on\nachieving high consistent frame rates to maximize user immersion.\n\nFor both high-fidelity and casual games, you should support battery saver mode\nto lengthen playtime by reducing your peak frame rates.\n\nDeclare support for Game Modes\n------------------------------\n\nTo declare support for Game Modes and override any Game Mode interventions by\nOEMs, first add the Game Mode configuration to the\n[`\u003capplication\u003e`](/guide/topics/manifest/application-element) element in your\n`AndroidManifest.xml` file: \n\n \u003capplication\u003e\n \u003cmeta-data android:name=\"android.game_mode_config\"\n android:resource=\"@xml/game_mode_config\" /\u003e\n ...\n \u003c/application\u003e\n\nThen create a `game_mode_config.xml` file in your project's `res/xml/` directory\nwith the following contents: \n\n \u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n \u003cgame-mode-config\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:supportsBatteryGameMode=\"true\"\n android:supportsPerformanceGameMode=\"true\"\n /\u003e\n\n| **Important:** If your game declares support for a Game Mode, the game must implement its own optimization. As a result, the platform resets any previously applied Game Mode interventions by OEMs.\n\nSwitch Game Modes\n-----------------\n\nTo switch between the game modes, you can use the Game Dashboard (available on\nPixel devices) or similar applications provided by OEMs. Alternatively you can\nuse the Game Mode shell command during development.\n\nIf you are using Game Dashboard and the **optimisation** icon does not display\nwhen your game launches, you may need to upload your app to Google Play Console\nand install it through the Play Store. For information about app testing in the\nPlay Store, see\n[Share app bundles and APKs internally](https://support.google.com/googleplay/android-developer/answer/9844679).\n\n\n**Figure 1.** Game Dashboard shown overlaying the running game on a Pixel\ndevice.\n\nIn figure 1, the running game's Game Mode can be changed from the Optimisation\nwidget. As shown on the widget, the game is currently running on\n[`PERFORMANCE`](https://developer.android.com/reference/android/app/GameManager#GAME_MODE_PERFORMANCE)\nmode.\n\nDuring development, if you are using a device without Game Dashboard and the\nmanufacturer does not provide any way to set Game Mode for each app, you can\nchange the Game Mode status through [adb](/studio/command-line/adb): \n\n adb shell cmd game mode [standard|performance|battery] \u003cPACKAGE_NAME\u003e\n\nSample Application\n------------------\n\nThe [Game Mode API sample](https://github.com/android/games-samples/tree/main/agdk/game_mode)\nhighlights how you can optimize FPS and render resolution caps to save approximately 25% power in your apps.\n\nNext\n----\n\nRead [Game Mode Interventions](/games/optimize/adpf/gamemode/gamemode-interventions)\nto improve a game's performance when it isn't possible to provide game updates."]]