Checking the Android Version on device at runtime

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: