Venkat Venkat - 1 year ago 90
Android Question

Android:how to find the android version name programmatically?

i write code for finding the android version like this

String version=Build.VERSION.RELEASE;

by using this code i am get the version number but i want version name.
how to get the version name???/

Answer Source

As suggested earlier, reflection seems to be the key to this question. The StringBuilder and extra formatting is not required, it was added only to illustrate usage.

import java.lang.reflect.Field;

StringBuilder builder = new StringBuilder();
builder.append("android : ").append(Build.VERSION.RELEASE);

Field[] fields = Build.VERSION_CODES.class.getFields();
for (Field field : fields) {
    String fieldName = field.getName();
    int fieldValue = -1;

    try {
        fieldValue = field.getInt(new Object());
    } catch (IllegalArgumentException e) {
    } catch (IllegalAccessException e) {
    } catch (NullPointerException e) {

    if (fieldValue == Build.VERSION.SDK_INT) {
        builder.append(" : ").append(fieldName).append(" : ");

Log.d(LOG_TAG, "OS: " + builder.toString());

On my 4.1 emulator, I get this output:

D/MainActivity( 1551): OS: android : 4.1.1 : JELLY_BEAN : sdk=16


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download