Applications may need to use APIs that are exclusive to specific versions of Android. Checking the version of Android that an app is currently running on allows the developer to cause different actions to occur depending on which operating system is installed on the device. This can be done by setting the compileSdkVersion, minSdkVersion, and targetSdkVersion in the build.gradle file of an Android Studio project, then determining which APIs should be used by checking the Android version at runtime.
Sample Code:
// build.gradle file android { compileSdkVersion 25 defaultConfig { minSdkVersion 21 targetSdkVersion 25 } } // java file public void checkAndroidVersion() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.NOUGAT) { // Code targeting FIRE OS 6 (NOUGAT) } else { // Code targeting FIRE OS 5 (LOLLIPOP) } }