DevicePerformance


interface DevicePerformance

Known direct subclasses
DefaultDevicePerformance

Reports the media performance class of the device.

FakeDevicePerformance

A DevicePerformance that immediately returns the mediaPerformanceClass.

PlayServicesDevicePerformance

A DevicePerformance that uses Google Play Services to retrieve media performance class data.


Reports the media performance class of the device.

Create an instance of DevicePerformance in your android.app.Application.onCreate and use the mediaPerformanceClass value any time it is needed.

import androidx.core.performance.DevicePerformance
import androidx.core.performance.play.services.PlayServicesDevicePerformance

class MyApplication : Application() {
    lateinit var devicePerformance: DevicePerformance

    override fun onCreate() {
        // use a DevicePerformance derived class
        devicePerformance = PlayServicesDevicePerformance(applicationContext)
    }
}

class MyActivity : Activity() {
    private lateinit var devicePerformance: DevicePerformance
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // Production applications should use a dependency framework.
        // See https://developer.android.com/training/dependency-injection for more information.
        devicePerformance = (application as MyApplication).devicePerformance
    }

    override fun onResume() {
        super.onResume()
        when {
            devicePerformance.mediaPerformanceClass >= Build.VERSION_CODES.TIRAMISU -> {
                // Provide the most premium experience for highest performing devices
            }
            devicePerformance.mediaPerformanceClass == Build.VERSION_CODES.R -> {
                // Provide a high quality experience
            }
            else -> {
                // Remove extras to keep experience functional
            }
        }
    }
}

Summary

Public properties

Int

The media performance class of the device or 0 if none.

Public properties

mediaPerformanceClass

Added in 1.0.0
val mediaPerformanceClassInt

The media performance class of the device or 0 if none.

If this value is not 0, the device conforms to the media performance class definition of the SDK version of this value. This value is stable for the duration of the process.

Possible non-zero values are defined in Build.VERSION_CODES starting with VERSION_CODES.R.

Defaults to VERSION.MEDIA_PERFORMANCE_CLASS