Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting device os version in Android programmatically

Tags:

java

android

How can I get the current android device version (1.5, 1.6, 2.0, etc.) programmatically? i.e I have installed my apk on an Android 2.2 device. I need to get the device version (android emulator version in which my application is currently running ).

like image 765
user629872 Avatar asked Sep 07 '11 03:09

user629872


People also ask

How can I get Android OS programmatically?

This example demonstrates How to get programmatically android version number. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do I find device info programmatically?

In Android one can easily fetch the information programmatically using Build class. Build class in android provides the basic information like serial number, android SDK, brand, model no, manufacture, version code and etc.

How do I find my Android API level?

If you are on at least API version 4 (Android 1.6 Donut), the current suggested way of getting the API level would be to check the value of android. os. Build. VERSION.


2 Answers

Something like these:

String myVersion = android.os.Build.VERSION.RELEASE; // e.g. myVersion := "1.6" int sdkVersion = android.os.Build.VERSION.SDK_INT; // e.g. sdkVersion := 8;  

You can retrieve all SDK codes from Build.VERSION_CODES

like image 183
Andrey Atapin Avatar answered Sep 25 '22 06:09

Andrey Atapin


int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP){     // Do something for lollipop and above versions } else{     // do something for phones running an SDK before lollipop } 

By this code we can execute separate code for Pre Lollipop devices.

like image 41
Vignesh KM Avatar answered Sep 23 '22 06:09

Vignesh KM