Last Updated: February 25, 2016
·
554
· keyboardsurfer

Make API level specific method calls more readable

When calling methods that require a specific API level, there is a widely spread pattern to do so:

if (Build.VERSION.SDK_INT > requiredApiLevel) {
  //api level specific code
}

You can also use the built in VERSION_CODES for this:

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
  //api level specific code
}