性能等级是 Android 12 中首次引入的标准。性能等级定义超出 Android 基准要求的一组设备功能。
每个 Android 版本都有自己对应的性能等级,这在相应版本的 Android 兼容性定义文档 (CDD) 中进行了定义。Android 兼容性测试套件 (CTS) 会验证 CDD 要求。
每部 Android 设备都会声明其支持的性能等级。开发者可以在运行时检查设备的性能等级,并提供充分利用设备功能的升级体验。
如需了解设备的性能等级,请使用 Jetpack Core Performance 库。此库会根据 build 版本信息中的声明或 Google Play 服务中的数据来报告设备的媒体性能等级 (MPC)。
首先,在 Gradle 文件中为相关模块添加依赖项:
// 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")
// 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'