Summary
Allow the version of Android to determine the APIs that are used.
Issue
Some APIs from Lollipop are incompatible with Kitkat and some APIs from Kitkat are incompatible with Lollipop.
Resolution
Set the compileSdkVersion, minSdkVersion, and targetSdkVersion in the build.gradle file of your Android Studio project, then determine which APIs should be used by checking the Android version at runtime.
Sample Code // build.gradle file
android { compileSdkVersion 21 defaultConfig { minSdkVersion 15 targetSdkVersion 21 } } [/pre] [pre] // java file
public void checkAndroidVersion() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ // Code targeting LOLLIPOP and above goes here } else { // Code targeting KITKAT and below goes here } } [/pre]
Keywords: Code Targeting, Manifests, Gradle
KB_0028