Android Checking the Android Version on device at runtime


Build.VERSION_CODES is an enumeration of the currently known SDK version codes.

In order to conditionally run code based on the device's Android version, use the TargetApi annotation to avoid Lint errors, and check the build version before running the code specific to the API level.

Here is an example of how to use a class that was introduced in API-23, in a project that supports API levels lower than 23:

public void onResume() {
    if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
        //run Marshmallow code
        FingerprintManager fingerprintManager = this.getSystemService(FingerprintManager.class);