Get Retrieving Android API OS Platform version programmatically

How to detect android mobile phone device operating system version name like marshmallow, lollipop, kitkat etc.

Till date 14th December 2016 android developers has launched 25 different API versions and they all keeps better and better with every update. So in this tutorial we are going to get the current installed os version from android device on button click event using android.os.Build.VERSION.SDK_INT method. This method will return the version code and with that particular code we would get the version name using a simple switch case. So here is the complete step by step tutorial for Get Retrieving Android API OS Platform version programmatically.

android-project-download-code-button

List of all version codes till 14th December 2016 :

Android Version NameVersionAPI Level
(no code name)1.0API level 1
(no code name)1.1API level 2
Cupcake1.5API level 3, NDK 1
Donut1.6API level 4, NDK 2
Eclair2.0API level 5
Eclair2.0.1API level 6
Eclair2.1API level 7, NDK 3
Froyo2.2xAPI level 8, NDK 4
Gingerbread2.3 - 2.3.2API level 9, NDK 5
Gingerbread2.3.3 - 2.3.7API level 10
Honeycomb3.0API level 11
Honeycomb3.1API level 12, NDK 6
Honeycomb3.2.xAPI level 13
Ice Cream Sandwich4.0.1 - 4.0.2API level 14, NDK 7
Ice Cream Sandwich4.0.3 - 4.0.4API level 15, NDK 8
Jelly Bean4.1.xAPI level 16
Jelly Bean4.2.xAPI level 17
Jelly Bean4.3.xAPI level 18
KitKat4.4 - 4.4.4API level 19
Lollipop5.0API level 21
Lollipop5.1API level 22
Marshmallow6.0API level 23
Nougat7.0API level 24
Nougat7.1API level 25

How to Get Retrieving Android API OS Platform version programmatically .

Code for MainActivity.java file.

package com.android_examples.getandroidosname_android_examplescom;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    Button button ;
    TextView textView;
    int CVersion ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button = (Button)findViewById(R.id.button);
        textView = (TextView)findViewById(R.id.textView);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                CVersion = android.os.Build.VERSION.SDK_INT;

               switch (CVersion){

                   case 11 :
                       textView.setText("Honeycomb");
                       break;

                   case 12 :
                       textView.setText("Honeycomb");
                       break;

                   case 13 :
                       textView.setText("Honeycomb");
                       break;

                   case 14 :
                       textView.setText("Ice Cream Sandwich");
                       break;

                   case 15 :
                       textView.setText("Ice Cream Sandwich");
                       break;

                   case 16 :
                       textView.setText("Jelly Bean");
                       break;

                   case 17 :
                       textView.setText("Jelly Bean");
                       break;

                   case 18 :
                       textView.setText("Jelly Bean");
                       break;

                   case 19 :
                       textView.setText("KitKat");
                       break;

                   case 21 :
                       textView.setText("Lollipop");
                       break;

                   case 22 :
                       textView.setText("Lollipop");
                       break;

                   case 23 :
                       textView.setText("Marshmallow");
                       break;

                   case 24 :
                       textView.setText("Nougat");
                       break;

                   case 25 :
                       textView.setText("Nougat");
                       break;

                       default:
                           Toast.makeText(MainActivity.this,"Not Found", Toast.LENGTH_LONG).show();
                           break;
               }

            }
        });
    }
}

Code for activity_main.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.android_examples.getandroidosname_android_examplescom.MainActivity"
    android:background="#FFF3E0">

    <Button
        android:text="get android api os version programmatically"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/button" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="63dp"
        android:id="@+id/textView"
        android:textSize="30dp"
        android:textColor="#000000"
        android:gravity="center"/>
</RelativeLayout>

Screenshot :

Get Retrieving Android API OS Platform version programmatically

Click here to download Get Retrieving Android API OS Platform version programmatically project with source code.

Leave a Reply

Your email address will not be published. Required fields are marked *