Class AndroidVersion
- java.lang.Object
-
- com.android.sdklib.AndroidVersion
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<AndroidVersion>
public final class AndroidVersion extends java.lang.Object implements java.lang.Comparable<AndroidVersion>, java.io.Serializable
Represents the version of a target or device.
A version is defined by an API level and an optional code name.- Release versions of the Android platform are identified by their API level (integer),
(technically the code name for release version is "REL" but this class will return
nullinstead.) - Preview versions of the platform are identified by a code name. Their API level is usually set to the value of the previous platform.
While this class contains both values, its goal is to abstract them, so that code comparing 2+ versions doesn't have to deal with the logic of handle both values.
There are some cases where ones may want to access the values directly. This can be done with
For generic UI display of the API version,getApiLevel()andgetCodename().getApiString()is to be used.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAndroidVersion.AndroidVersionExceptionThrown when anAndroidVersionobject could not be created.static classAndroidVersion.VersionCodesSDK version codes mirroring ones found in Build#VERSION_CODES on Android.
-
Field Summary
Fields Modifier and Type Field Description static AndroidVersionALLOW_SPLIT_APK_INSTALLATIONFirst version to allow split apksstatic AndroidVersionART_RUNTIMEFirst version to use ART by default.static AndroidVersionBINDER_CMD_AVAILABLEFirst version to feature binder's common interface "cmd" for sending shell commands to services.static AndroidVersionDEFAULTThe default AndroidVersion for minSdkVersion and targetSdkVersion if not specified.static intMIN_FOLDABLE_DEVICE_APIFrist version to support Foldable devicestatic intMIN_FREEFORM_DEVICE_APIFirst version to support freeform displaystatic intMIN_HINGE_FOLDABLE_DEVICE_APIFirst version to support hinge foldable settingsstatic intMIN_PIXEL_4A_DEVICE_APIFirst version to support pixel 4astatic intMIN_RECOMMENDED_APIMinimum API versions that are recommended for use in testing appsstatic intMIN_RECOMMENDED_WEAR_APIstatic AndroidVersionSUPPORTS_64_BITFirst version to support 64-bit ABIs.static AndroidVersionSUPPORTS_MULTI_USERFirst version to have multi-user support (JB-MR2, API 17)
-
Constructor Summary
Constructors Constructor Description AndroidVersion(int apiLevel)Creates anAndroidVersionwith the given api level of a release version (the codename is null).AndroidVersion(int apiLevel, java.lang.String codename)Creates anAndroidVersionwith the given api level and codename.AndroidVersion(java.lang.String apiOrCodename)Creates anAndroidVersionfrom a string that may be an integer API level or a string codename.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanRun(AndroidVersion appVersion)Checks whether a device running a version similar to the receiver can run a project compiled for the given version.intcompareTo(int apiLevel, java.lang.String codename)intcompareTo(AndroidVersion o)Compares this object with the specified object for order.booleanequals(int apiLevel)Returnstrueif the AndroidVersion is an API level equals to apiLevel.booleanequals(java.lang.Object obj)intgetApiLevel()Returns the api level as an integer.java.lang.StringgetApiString()Returns a string representing the API level and/or the code name.java.lang.StringgetCodename()Returns the version code name if applicable, null otherwise.intgetFeatureLevel()Returns the API level as an integer.inthashCode()booleanisGreaterOrEqualThan(int api)Compares this version with the specified API and returns true if this version is greater or equal than the requested API -- that is the current version is a suitable min-api-level for the argument API.booleanisLegacyMultidex()Checks if the version is having legacy multidex support.booleanisPreview()Returns whether or not the version is a preview version.java.lang.StringtoString()Returns a string with the API Level and optional codename.
-
-
-
Field Detail
-
DEFAULT
public static final AndroidVersion DEFAULT
The default AndroidVersion for minSdkVersion and targetSdkVersion if not specified.
-
ART_RUNTIME
public static final AndroidVersion ART_RUNTIME
First version to use ART by default.
-
SUPPORTS_64_BIT
public static final AndroidVersion SUPPORTS_64_BIT
First version to support 64-bit ABIs.
-
BINDER_CMD_AVAILABLE
public static final AndroidVersion BINDER_CMD_AVAILABLE
First version to feature binder's common interface "cmd" for sending shell commands to services.
-
ALLOW_SPLIT_APK_INSTALLATION
public static final AndroidVersion ALLOW_SPLIT_APK_INSTALLATION
First version to allow split apks
-
SUPPORTS_MULTI_USER
public static final AndroidVersion SUPPORTS_MULTI_USER
First version to have multi-user support (JB-MR2, API 17)
-
MIN_RECOMMENDED_API
public static final int MIN_RECOMMENDED_API
Minimum API versions that are recommended for use in testing apps- See Also:
- Constant Field Values
-
MIN_RECOMMENDED_WEAR_API
public static final int MIN_RECOMMENDED_WEAR_API
- See Also:
- Constant Field Values
-
MIN_FOLDABLE_DEVICE_API
public static final int MIN_FOLDABLE_DEVICE_API
Frist version to support Foldable device- See Also:
- Constant Field Values
-
MIN_FREEFORM_DEVICE_API
public static final int MIN_FREEFORM_DEVICE_API
First version to support freeform display- See Also:
- Constant Field Values
-
MIN_HINGE_FOLDABLE_DEVICE_API
public static final int MIN_HINGE_FOLDABLE_DEVICE_API
First version to support hinge foldable settings- See Also:
- Constant Field Values
-
MIN_PIXEL_4A_DEVICE_API
public static final int MIN_PIXEL_4A_DEVICE_API
First version to support pixel 4a- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AndroidVersion
public AndroidVersion(int apiLevel, @Nullable java.lang.String codename)Creates anAndroidVersionwith the given api level and codename. Codename should be null for a release version, otherwise it's a preview codename.
-
AndroidVersion
public AndroidVersion(int apiLevel)
Creates anAndroidVersionwith the given api level of a release version (the codename is null).
-
AndroidVersion
public AndroidVersion(@NonNull java.lang.String apiOrCodename) throws AndroidVersion.AndroidVersionExceptionCreates anAndroidVersionfrom a string that may be an integer API level or a string codename. Important: An important limitation of this method is that cannot possible recreate the API level integer from a pure string codename. This is only OK to use if the caller can guarantee that onlygetApiString()will be used later. Wrong things will happen if the caller then tries to resolve the numericgetApiLevel().- Parameters:
apiOrCodename- A non-null API integer or a codename in its "ALL_CAPS" format. "REL" is notable not a valid codename.- Throws:
AndroidVersion.AndroidVersionException- if the input isn't a pure integer or doesn't look like a valid string codename.
-
-
Method Detail
-
getApiLevel
public int getApiLevel()
Returns the api level as an integer.For target that are in preview mode, this can be superseded by
getCodename().To display the API level in the UI, use
getApiString(), which will use the codename if applicable.- See Also:
getCodename(),getApiString()
-
getFeatureLevel
public int getFeatureLevel()
Returns the API level as an integer. If this is a preview platform, it will return the expected final version of the API rather than the current API level. This is the "feature level" as opposed to the "release level" returned bygetApiLevel()in the sense that it is useful when you want to check the presence of a given feature from an API, and we consider the feature present in preview platforms as well.- Returns:
- the API level of this version, +1 for preview platforms
-
getCodename
@Nullable public java.lang.String getCodename()
Returns the version code name if applicable, null otherwise.If the codename is non null, then the API level should be ignored, and this should be used as a unique identifier of the target instead.
-
getApiString
@NonNull public java.lang.String getApiString()
Returns a string representing the API level and/or the code name.
-
isPreview
public boolean isPreview()
Returns whether or not the version is a preview version.
-
isLegacyMultidex
public boolean isLegacyMultidex()
Checks if the version is having legacy multidex support.
-
canRun
public boolean canRun(@NonNull AndroidVersion appVersion)Checks whether a device running a version similar to the receiver can run a project compiled for the given version.Be aware that this is not a perfect test, as other properties could break compatibility despite this method returning true.
Nevertheless, when testing if an application can run on a device (where there is no access to the list of optional libraries), this method can give a good indication of whether there is a chance the application could run, or if there's a direct incompatibility.
-
equals
public boolean equals(int apiLevel)
Returnstrueif the AndroidVersion is an API level equals to apiLevel.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
Returns a string with the API Level and optional codename. Useful for debugging. For display purpose, please usegetApiString()instead.- Overrides:
toStringin classjava.lang.Object
-
compareTo
public int compareTo(@NonNull AndroidVersion o)Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.- Specified by:
compareToin interfacejava.lang.Comparable<AndroidVersion>- Parameters:
o- the Object to be compared.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
-
compareTo
public int compareTo(int apiLevel, @Nullable java.lang.String codename)
-
isGreaterOrEqualThan
public boolean isGreaterOrEqualThan(int api)
Compares this version with the specified API and returns true if this version is greater or equal than the requested API -- that is the current version is a suitable min-api-level for the argument API.
-
-