Stay organized with collections Save and categorize content based on your preferences.

DevicePerformance

public interface DevicePerformance


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.

class MyApplication : Application() {

    private lateinit var devicePerformance: DevicePerformance

    override fun onCreate() {
        devicePerformance = DevicePerformance.create(applicationContext)
    }

    fun doSomeThing() {
        when {
            devicePerformance.mediaPerformanceClass >= Build.VERSION_CODES.S -> {
                // 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

Nested types

public static class DevicePerformance.Companion

Public methods

default static final @NonNull DevicePerformance

Create PerformanceClass from the context.

abstract int

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

Public methods

create

default static final @NonNull DevicePerformance create(@NonNull Context context)

Create PerformanceClass from the context.

This should be done in android.app.Application.onCreate.

Parameters
@NonNull Context context

The ApplicationContext.

getMediaPerformanceClass

abstract int getMediaPerformanceClass()

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