Is there any way to get the API version that the phone is currently running?
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”).
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.
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.
Android 8.0 (API level 26)
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
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 );
E/MyActivity: manufacturer ManufacturerX model SM-T310 version 19 versionRelease 4.4.2
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