Programmatically obtain the Android API level of a device?

You can obtain API level programatically by the system constant (Build.VERSION.SDK_INT). For example you can run some piece of code which requires newer API in the following way (it will execute if the current device’s API level is at least 4)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.DONUT) {

}

To obtain user visible Android Version use:

Build.VERSION.RELEASE

Leave a Comment