Java tutorial
//package com.java2s; import android.os.Build; import java.lang.reflect.Field; public class Main { static int _version = -1; static int getApiLevel() { if (_version < 0) { try { Field SDK_INT_field = Build.VERSION.class.getField("SDK_INT"); _version = (Integer) SDK_INT_field.get(null); } catch (Exception ignored) { _version = 3; } } return _version; } }