com.android.sdklib

Class AndroidVersion

    • Constructor Summary

      Constructors 
      Constructor and Description
      AndroidVersion(int apiLevel, java.lang.String codename)
      Creates an AndroidVersion with the given api level and codename.
      AndroidVersion(java.util.Properties properties)
      Creates an AndroidVersion from Properties.
      AndroidVersion(java.util.Properties properties, int defaultApiLevel, java.lang.String defaultCodeName)
      Creates an AndroidVersion from Properties, with default values if the Properties object doesn't contain the expected values.
      AndroidVersion(java.lang.String apiOrCodename)
      Creates an AndroidVersion from a string that may be an integer API level or a string codename.
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      boolean canRun(AndroidVersion appVersion)
      Checks whether a device running a version similar to the receiver can run a project compiled for the given version.
      int compareTo(AndroidVersion o)
      Compares this object with the specified object for order.
      int compareTo(int apiLevel, java.lang.String codename) 
      boolean equals(int apiLevel)
      Returns true if the AndroidVersion is an API level equals to apiLevel.
      boolean equals(java.lang.Object obj)
      Compares the receiver with either an AndroidVersion object or a String object.
      int getApiLevel()
      Returns the api level as an integer.
      java.lang.String getApiString()
      Returns a string representing the API level and/or the code name.
      java.lang.String getCodename()
      Returns the version code name if applicable, null otherwise.
      int hashCode() 
      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.
      boolean isPreview()
      Returns whether or not the version is a preview version.
      void saveProperties(java.util.Properties props) 
      java.lang.String toString()
      Returns a string with the API Level and optional codename.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • AndroidVersion

        public AndroidVersion(int apiLevel,
                      @Nullable
                      java.lang.String codename)
        Creates an AndroidVersion with the given api level and codename. Codename should be null for a release version, otherwise it's a preview codename.
      • AndroidVersion

        public AndroidVersion(@Nullable
                      java.util.Properties properties,
                      int defaultApiLevel,
                      @Nullable
                      java.lang.String defaultCodeName)
        Creates an AndroidVersion from Properties, with default values if the Properties object doesn't contain the expected values.

        The Properties is expected to have been filled with saveProperties(Properties).

      • AndroidVersion

        public AndroidVersion(@NonNull
                      java.lang.String apiOrCodename)
                       throws AndroidVersion.AndroidVersionException
        Creates an AndroidVersion from 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 only getApiString() will be used later. Wrong things will happen if the caller then tries to resolve the numeric getApiLevel().

        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

      • saveProperties

        public void saveProperties(@NonNull
                          java.util.Properties props)
      • 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()
      • 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.
      • 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. For a more comprehensive test, see IAndroidTarget.canRunOn(IAndroidTarget).

        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)
        Returns true if the AndroidVersion is an API level equals to apiLevel.
      • equals

        public boolean equals(java.lang.Object obj)
        Compares the receiver with either an AndroidVersion object or a String object.

        If obj is a String, then the method will first check if it's a string representation of a number, in which case it'll compare it to the api level. Otherwise, it'll compare it against the code name.

        For all other type of object give as parameter, this method will return false.

        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.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 use getApiString() instead.
        Overrides:
        toString in class java.lang.Object
      • compareTo

        public int compareTo(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:
        compareTo in interface java.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.