It's very easy to add version checks in Anko, and Anko provides two main functions for it:
- doIfSdk : This takes in the version code as a parameter, and also a function. If the API level of device is equal to the version code supplied, the function is executed. Here's an example of this function:
doIfSdk(Build.VERSION_CODES.LOLLIPOP){ // Do something specific to version 21}
- doFromSdk : This also takes in the version code as a parameter, along with the function, and executes that function if the device SDK level is greater than or equal to the supplied version code. The following is an example of the same:
doFromSdk(Build.VERSION_CODES.LOLLIPOP){ // Execute this method on API >=21}