As described in the android documentation, the SDK level (integer) the phone is running is available in:
android.os.Build.VERSION.SDK_INT;
The enum corresponding to this int is in the android.os.Build.VERSION_CODES class.
Code example:
int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= android.os.Build.VERSION_CODES.FROYO){ // Do something for froyo and above versions } else{ // do something for phones running an SDK before froyo }
Edit: This SDK_INT is available since Donut (android 1.6 / API4) so make sure your application is not retro-compatible with Cupcake (android 1.5 / API3) when you use it or your application will crash (thanks to Programmer Bruce for the precision).
Corresponding android documentation: