// Implementation of Jetpack Core library.implementation("androidx.core:core-ktx:1.12.0")// Enable APIs to query for device-reported performance class.implementation("androidx.core:core-performance:1.0.0")// Enable APIs to query Google Play services for performance class.implementation("androidx.core:core-performance-play-services:1.0.0")
Groovy
// Implementation of Jetpack Core library.implementation'androidx.core:core-ktx:1.12.0'// Enable APIs to query for device-reported performance class.implementation'androidx.core:core-performance:1.0.0'// Enable APIs to query Google Play services for performance class.implementation'androidx.core:core-performance-play-services:1.0.0'
importandroidx.core.performance.play.services.PlayServicesDevicePerformanceclassMyApplication:Application(){lateinitvardevicePerformance:DevicePerformanceoverridefunonCreate(){// Use a class derived from the DevicePerformance interfacedevicePerformance=PlayServicesDevicePerformance(applicationContext)}}
Java
importandroidx.core.performance.play.services.PlayServicesDevicePerformance;classMyApplicationextendsApplication{DevicePerformancedevicePerformance;@OverridepublicvoidonCreate(){// Use a class derived from the DevicePerformance interfacedevicePerformance=newPlayServicesDevicePerformance(applicationContext);}}
然后,您可以检索 mediaPerformanceClass 属性,以根据设备的功能定制应用体验:
Kotlin
classMyActivity:Activity(){privatelateinitvardevicePerformance:DevicePerformanceoverridefunonCreate(savedInstanceState:Bundle?){super.onCreate(savedInstanceState)// Note: Good app architecture is to use a dependency framework. See// https://developer.android.com/training/dependency-injection for more// information.devicePerformance=(applicationasMyApplication).devicePerformance}overridefunonResume(){super.onResume()when{devicePerformance.mediaPerformanceClass>=Build.VERSION_CODES.VANILLA_ICE_CREAM->{// MPC level 35 and later.// Provide the most premium experience for the highest performing devices.}devicePerformance.mediaPerformanceClass==Build.VERSION_CODES.UPSIDE_DOWN_CAKE->{// MPC level 34.// Provide a high quality experience.}else->{// MPC level 33, 31, 30, or undefined.// Remove extras to keep experience functional.}}}}
Java
classMyActivityextendsActivity{privateDevicePerformancedevicePerformance;@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);// Note: Good app architecture is to use a dependency framework. See// https://developer.android.com/training/dependency-injection for more// information.devicePerformance=((MyApplication)getApplication()).devicePerformance;}@OverridepublicvoidonResume(){super.onResume();if(devicePerformance.getMediaPerformanceClass()>=Build.VERSION_CODES.VANILLA_ICE_CREAM){// MPC level 35 and later.// Provide the most premium experience for the highest performing devices.}elseif(devicePerformance.getMediaPerformanceClass()==Build.VERSION_CODES.UPSIDE_DOWN_CAKE){// MPC level 34.// Provide a high quality experience.}else{// MPC level 33, 31, 30, or undefined.// Remove extras to keep experience functional.}}}
[[["易于理解","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"]],["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Performance class\n\n*Performance class* is a standard first introduced in Android 12. A performance\nclass defines a set of device capabilities that goes beyond Android's baseline\nrequirements.\n\nEach version of Android has its own corresponding performance class, which is\ndefined in that version's [Android Compatibility Definition Document\n(CDD)](https://source.android.com/compatibility/cdd). The [Android Compatibility\nTest Suite (CTS)](https://source.android.com/compatibility/cts) verifies the\nCDD requirements.\n\nEach Android-powered device declares the performance class that it supports.\nDevelopers can find the device's performance class at runtime and provide\nupgraded experiences that take full advantage of the device's capabilities.\n\nTo find a device's performance class level, use the Jetpack [Core\nPerformance](/jetpack/androidx/releases/core#core_performance_version_10_2)\nlibrary. This library reports the device's media performance class (MPC) level\nas declared in the\n[build version information](/reference/android/os/Build.VERSION#MEDIA_PERFORMANCE_CLASS)\nor based on data from Google Play services.\n\nStart by adding a dependency for the relevant modules in your gradle file: \n\n### Kotlin\n\n```kotlin\n// Implementation of Jetpack Core library.\nimplementation(\"androidx.core:core-ktx:1.12.0\")\n// Enable APIs to query for device-reported performance class.\nimplementation(\"androidx.core:core-performance:1.0.0\")\n// Enable APIs to query Google Play services for performance class.\nimplementation(\"androidx.core:core-performance-play-services:1.0.0\")\n```\n\n### Groovy\n\n```groovy\n// Implementation of Jetpack Core library.\nimplementation 'androidx.core:core-ktx:1.12.0'\n// Enable APIs to query for device-reported performance class.\nimplementation 'androidx.core:core-performance:1.0.0'\n// Enable APIs to query Google Play services for performance class.\nimplementation 'androidx.core:core-performance-play-services:1.0.0'\n```\n\nThen, create an instance of a\n[`DevicePerformance`](/reference/androidx/core/performance/DevicePerformance)\nimplementation, such as\n[`PlayServicesDevicePerformance`](/reference/androidx/core/performance/play/services/PlayServicesDevicePerformance),\nin the `onCreate()` lifecycle event of your `Application`. This should only be\ndone once in your app. \n\n### Kotlin\n\n```kotlin\nimport androidx.core.performance.play.services.PlayServicesDevicePerformance\n\nclass MyApplication : Application() {\n lateinit var devicePerformance: DevicePerformance\n\n override fun onCreate() {\n // Use a class derived from the DevicePerformance interface\n devicePerformance = PlayServicesDevicePerformance(applicationContext)\n }\n}\n```\n\n### Java\n\n```java\nimport androidx.core.performance.play.services.PlayServicesDevicePerformance;\n\nclass MyApplication extends Application {\n DevicePerformance devicePerformance;\n\n @Override\n public void onCreate() {\n // Use a class derived from the DevicePerformance interface\n devicePerformance = new PlayServicesDevicePerformance(applicationContext);\n }\n}\n```\n\nYou can then retrieve the `mediaPerformanceClass` property to tailor your app's\nexperience based on the device's capabilities: \n\n### Kotlin\n\n```kotlin\nclass MyActivity : Activity() {\n private lateinit var devicePerformance: DevicePerformance\n override fun onCreate(savedInstanceState: Bundle?) {\n super.onCreate(savedInstanceState)\n // Note: Good app architecture is to use a dependency framework. See\n // https://developer.android.com/training/dependency-injection for more\n // information.\n devicePerformance = (application as MyApplication).devicePerformance\n }\n\n override fun onResume() {\n super.onResume()\n when {\n devicePerformance.mediaPerformanceClass \u003e= Build.VERSION_CODES.VANILLA_ICE_CREAM -\u003e {\n // MPC level 35 and later.\n // Provide the most premium experience for the highest performing devices.\n }\n devicePerformance.mediaPerformanceClass == Build.VERSION_CODES.UPSIDE_DOWN_CAKE -\u003e {\n // MPC level 34.\n // Provide a high quality experience.\n }\n else -\u003e {\n // MPC level 33, 31, 30, or undefined.\n // Remove extras to keep experience functional.\n }\n }\n }\n}\n```\n\n### Java\n\n```java\nclass MyActivity extends Activity {\n private DevicePerformance devicePerformance;\n @Override\n public void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n // Note: Good app architecture is to use a dependency framework. See\n // https://developer.android.com/training/dependency-injection for more\n // information.\n devicePerformance = ((MyApplication) getApplication()).devicePerformance;\n }\n\n @Override\n public void onResume() {\n super.onResume();\n if (devicePerformance.getMediaPerformanceClass() \u003e= Build.VERSION_CODES.VANILLA_ICE_CREAM) {\n // MPC level 35 and later.\n // Provide the most premium experience for the highest performing devices.\n } else if (devicePerformance.getMediaPerformanceClass() == Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {\n // MPC level 34.\n // Provide a high quality experience.\n } else {\n // MPC level 33, 31, 30, or undefined.\n // Remove extras to keep experience functional.\n }\n }\n}\n```\n\nPerformance class levels are forward-compatible. A device can upgrade to a newer\nplatform version without updating its performance class. For example, a device\nthat initially supports performance class 33 can upgrade to Android 14 and\ncontinue to report it supports performance class 33 if it doesn't meet the\nperformance class 34 requirements. This allows grouping devices together without\nrelying on a particular Android version.\n\n\n**Figure 1.** Devices can upgrade Android versions and continue reporting that they support the class they originally support.\n\n\u003cbr /\u003e\n\nMedia Performance Class 35\n--------------------------\n\nMPC 35 was introduced in Android 15 and builds on the requirements\nintroduced in [MPC 34](#class-34). The specific MPC 35 requirements are\npublished in the\n[Android 15 CDD](https://source.android.com/docs/compatibility/15/android-15-cdd#227_handheld_media_performance_class).\nIn addition to increased requirements for items from MPC 34, the CDD specifies\nrequirements in the following areas:\n\n### Media\n\n- Decoding frame drops\n- HDR editing\n- Dynamic color aspects\n- Portrait aspect ratio\n\n### Camera\n\n- JPEG_R\n- Preview stabilization\n\n### Graphics\n\n- EGL extensions\n- Vulkan structures\n\nMedia Performance Class 34\n--------------------------\n\nMPC 34 was introduced in Android 14 and builds on the requirements\nintroduced in [MPC 33](#class-33). The specific MPC 34 requirements are\npublished in the\n[Android 14 CDD](https://source.android.com/docs/compatibility/14/android-14-cdd#227_handheld_media_performance_class).\nIn addition to increased requirements for items from MPC 33, the CDD specifies\nrequirements in the following areas:\n\n### Media\n\n- Film grain effect support in AV1 hardware decoders\n- AVIF Baseline Profile\n- AV1 encoder performance\n- HDR video codecs\n- RGBA_1010102 color format\n- YUV texture sampling\n- Video encoding quality\n- Multichannel audio mixing\n\n### Camera\n\n- Night mode extension\n- HDR-capable primary camera\n- Face detection scene mode\n\n### General\n\n- Hardware overlays\n- HDR display\n\nMedia Performance Class 33\n--------------------------\n\nMPC 33 was introduced in Android 13 and builds on the requirements\nintroduced in [MPC 31](#class-31). The specific MPC 33 requirements are\npublished in the\n[Android 13 CDD](https://source.android.com/docs/compatibility/13/android-13-cdd#227_handheld_media_performance_class).\nIn addition to increased requirements for items from MPC 31, the CDD specifies\nrequirements in the following areas:\n\n### Media\n\n- AV1 hardware decoder\n- Secure hardware decoders\n- Decoder initialization latency\n- Round-trip audio latency\n- Wired headsets and USB audio devices\n- MIDI devices\n- Hardware-backed trusted execution environment\n\n### Camera\n\n- Preview stabilization\n- Slow-mo recording\n- Minimum zoom ratio for ultrawide cameras\n- Concurrent camera\n- Logical multi-camera\n- Stream use case\n\n| **Note:** There is no MPC level 32 definition.\n\nMedia Performance Class 31\n--------------------------\n\nMPC 31 was introduced in Android 12. The specific MPC 31 requirements are\npublished in the\n[Android 12 CDD](https://source.android.com/docs/compatibility/12/android-12-cdd#227_handheld_media_performance_class).\nThe CDD specifies requirements in the following areas:\n\n### Media\n\n- Concurrent video codec sessions\n- Encoder initialization latency\n- Decoder frame drops\n- Encoding quality\n\n### Camera\n\n- Resolution and frame rate\n- Startup and capture latencies\n- [`FULL`](/reference/android/hardware/camera2/CameraMetadata#INFO_SUPPORTED_HARDWARE_LEVEL_FULL) or better hardware level\n- Timestamp source is realtime\n- RAW capability\n\n### General\n\n- Memory\n- Read and write performance\n- Screen resolution\n- Screen density\n\nMedia Performance Class 30\n--------------------------\n\nMPC 30 includes a subset of the requirements for MPC 31, letting developers\nprovide a tailored experience on earlier but still highly capable devices. The\nspecific performance class requirements are published in the\n[Android 11 CDD](https://source.android.com/docs/compatibility/11/android-11-cdd#227_handheld_media_performance_class).\n| **Note:** There are no MPC level definitions prior to MPC 30. An MPC level of 0 indicates that the MPC level is undefined for the current device and build.\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [App startup time](/topic/performance/vitals/launch-time)"]]