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

BuildCompat

public class BuildCompat


This class contains additional platform version checking methods for targeting pre-release versions of Android.

Summary

Nested types

Experimental feature set for pre-release SDK checks.

Constants

static final int
@ChecksSdkIntAtLeast(extension = SdkExtensions.AD_SERVICES)
AD_SERVICES_EXTENSION_INT

The value of SdkExtensions.getExtensionVersion(AD_SERVICES).

static final int
@ChecksSdkIntAtLeast(extension = Build.VERSION_CODES.R)
R_EXTENSION_INT

The value of SdkExtensions.getExtensionVersion(R).

static final int
@ChecksSdkIntAtLeast(extension = Build.VERSION_CODES.S)
S_EXTENSION_INT

The value of SdkExtensions.getExtensionVersion(S).

static final int
@ChecksSdkIntAtLeast(extension = Build.VERSION_CODES.TIRAMISU)
T_EXTENSION_INT

The value of SdkExtensions.getExtensionVersion(TIRAMISU).

Public methods

static boolean
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.N)
isAtLeastN()

This method is deprecated.

Android N is a finalized release and this method is no longer necessary.

static boolean
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.N_MR1)
isAtLeastNMR1()

This method is deprecated.

Android N MR1 is a finalized release and this method is no longer necessary.

static boolean
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.O)
isAtLeastO()

This method is deprecated.

Android O is a finalized release and this method is no longer necessary.

static boolean
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.O_MR1)
isAtLeastOMR1()

This method is deprecated.

Android O MR1 is a finalized release and this method is no longer necessary.

static boolean
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.P)
isAtLeastP()

This method is deprecated.

Android P is a finalized release and this method is no longer necessary.

static boolean
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.Q)
isAtLeastQ()

This method is deprecated.

Android Q is a finalized release and this method is no longer necessary.

static boolean
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.R)
isAtLeastR()

This method is deprecated.

Android R is a finalized release and this method is no longer necessary.

static boolean
@ChecksSdkIntAtLeast(api = 31, codename = "S")
isAtLeastS()

This method is deprecated.

Android S is a finalized release and this method is no longer necessary.

static boolean

This method is deprecated.

Android Sv2 is a finalized release and this method is no longer necessary.

static boolean
@BuildCompat.PrereleaseSdkCheck
@ChecksSdkIntAtLeast(api = 33, codename = "Tiramisu")
isAtLeastT()

Checks if the device is running on a pre-release version of Android Tiramisu or a release version of Android Tiramisu or newer.

static boolean

Checks if the device is running on a pre-release version of Android U.

Constants

AD_SERVICES_EXTENSION_INT

@ChecksSdkIntAtLeast(extension = SdkExtensions.AD_SERVICES)
public static final int AD_SERVICES_EXTENSION_INT

The value of SdkExtensions.getExtensionVersion(AD_SERVICES). This is a convenience constant which provides the extension version in a similar style to Build.VERSION.SDK_INT.

Compared to calling getExtensionVersion directly, using this constant has the benefit of not having to verify the getExtensionVersion method is available.

Returns
int

the version of the AdServices extension, if it exists. 0 otherwise.

R_EXTENSION_INT

@ChecksSdkIntAtLeast(extension = Build.VERSION_CODES.R)
public static final int R_EXTENSION_INT

The value of SdkExtensions.getExtensionVersion(R). This is a convenience constant which provides the extension version in a similar style to Build.VERSION.SDK_INT.

Compared to calling getExtensionVersion directly, using this constant has the benefit of not having to verify the getExtensionVersion method is available.

Returns
int

the version of the R extension, if it exists. 0 otherwise.

S_EXTENSION_INT

@ChecksSdkIntAtLeast(extension = Build.VERSION_CODES.S)
public static final int S_EXTENSION_INT

The value of SdkExtensions.getExtensionVersion(S). This is a convenience constant which provides the extension version in a similar style to Build.VERSION.SDK_INT.

Compared to calling getExtensionVersion directly, using this constant has the benefit of not having to verify the getExtensionVersion method is available.

Returns
int

the version of the S extension, if it exists. 0 otherwise.

T_EXTENSION_INT

@ChecksSdkIntAtLeast(extension = Build.VERSION_CODES.TIRAMISU)
public static final int T_EXTENSION_INT

The value of SdkExtensions.getExtensionVersion(TIRAMISU). This is a convenience constant which provides the extension version in a similar style to Build.VERSION.SDK_INT.

Compared to calling getExtensionVersion directly, using this constant has the benefit of not having to verify the getExtensionVersion method is available.

Returns
int

the version of the T extension, if it exists. 0 otherwise.

Public methods

isAtLeastN

@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.N)
public static boolean isAtLeastN()

Checks if the device is running on the Android N release or newer.

Returns
boolean

true if N APIs are available for use

isAtLeastNMR1

@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.N_MR1)
public static boolean isAtLeastNMR1()

Checks if the device is running on the Android N MR1 release or newer.

Returns
boolean

true if N MR1 APIs are available for use

isAtLeastO

@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.O)
public static boolean isAtLeastO()

Checks if the device is running on a release version of Android O or newer.

Returns
boolean

true if O APIs are available for use, false otherwise

isAtLeastOMR1

@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.O_MR1)
public static boolean isAtLeastOMR1()

Checks if the device is running on a release version of Android O MR1 or newer.

Returns
boolean

true if O MR1 APIs are available for use, false otherwise

isAtLeastP

@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.P)
public static boolean isAtLeastP()

Checks if the device is running on a release version of Android P or newer.

Returns
boolean

true if P APIs are available for use, false otherwise

isAtLeastQ

@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.Q)
public static boolean isAtLeastQ()

Checks if the device is running on release version of Android Q or newer.

Returns
boolean

true if Q APIs are available for use, false otherwise

isAtLeastR

@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.R)
public static boolean isAtLeastR()

Checks if the device is running on release version of Android R or newer.

Returns
boolean

true if R APIs are available for use, false otherwise

isAtLeastS

@ChecksSdkIntAtLeast(api = 31, codename = "S")
public static boolean isAtLeastS()

Checks if the device is running on a pre-release version of Android S or a release version of Android S or newer.

Returns
boolean

true if S APIs are available for use, false otherwise

isAtLeastSv2

@BuildCompat.PrereleaseSdkCheck
@ChecksSdkIntAtLeast(api = 32, codename = "Sv2")
public static boolean isAtLeastSv2()

Checks if the device is running on a pre-release version of Android Sv2 or a release version of Android Sv2 or newer.

Returns
boolean

true if Sv2 APIs are available for use, false otherwise

isAtLeastT

@BuildCompat.PrereleaseSdkCheck
@ChecksSdkIntAtLeast(api = 33, codename = "Tiramisu")
public static boolean isAtLeastT()

Checks if the device is running on a pre-release version of Android Tiramisu or a release version of Android Tiramisu or newer.

Note: When Android Tiramisu is finalized for release, this method will be removed and all calls must be replaced with Build.VERSION.SDK_INT >= 33.

Returns
boolean

true if Tiramisu APIs are available for use, false otherwise

isAtLeastU

@BuildCompat.PrereleaseSdkCheck
@ChecksSdkIntAtLeast(codename = "UpsideDownCake")
public static boolean isAtLeastU()

Checks if the device is running on a pre-release version of Android U.

Note: When Android U is finalized for release, this method will be removed and all calls must be replaced with Build.VERSION.SDK_INT >= Build.VERSION_CODES.U.

Returns
boolean

true if U APIs are available for use, false otherwise