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 ).
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.
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With