Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving Android API version programmatically

Is there any way to get the API version that the phone is currently running?

like image 913
Parth Mehta Avatar asked Aug 06 '10 12:08

Parth Mehta


People also ask

How do I know my Android API version?

Navigate to “Appearance & Behavior” > “System Settings” > “Android SDK” and now you can see the SDK versions that were installed in the “API Level” and “Name” columns (focus on “API Level”).

How can I get Android os programmatically?

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 the above code, we have taken text view to show device version number.

What is API Android version?

API Level is an integer value that uniquely identifies the framework API revision offered by a version of the Android platform. The Android platform provides a framework API that applications can use to interact with the underlying Android system.

What version of Android is API 26?

Android 8.0 (API level 26)


2 Answers

As described in the Android documentation, the SDK level (integer) the phone is running is available in:

android.os.Build.VERSION.SDK_INT

The class corresponding to this int is in the android.os.Build.VERSION_CODES class.

Code example:

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

Edit: This SDK_INT is available since Donut (android 1.6 / API4) so make sure your application is not retro-compatible with Cupcake (android 1.5 / API3) when you use it or your application will crash (thanks to Programmer Bruce for the precision).

Corresponding android documentation is here and here

like image 70
ol_v_er Avatar answered Sep 19 '22 16:09

ol_v_er


Very easy:

   String manufacturer = Build.MANUFACTURER;    String model = Build.MODEL;    int version = Build.VERSION.SDK_INT;    String versionRelease = Build.VERSION.RELEASE;  Log.e("MyActivity", "manufacturer " + manufacturer             + " \n model " + model             + " \n version " + version             + " \n versionRelease " + versionRelease     ); 

Output:

E/MyActivity:   manufacturer ManufacturerX                 model SM-T310                  version 19                  versionRelease 4.4.2 
like image 45
CommonSenseCode Avatar answered Sep 20 '22 16:09

CommonSenseCode