Reputation: 131
i want to check the version of android operating system installed on user device. can i find it using android.os.Build.VERSION_CODES or something else. please provide code.
Upvotes: 1
Views: 66
Reputation: 387
As described on Android Documentation API level can be retrieved using
android.os.Build.VERSION.SDK_INT
The class corresponding to this int is in the android.os.Build.VERSION_CODES class.
Code example:
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
Log.d("sdk version",""+currentapiVersion );
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
}
Upvotes: 1
Reputation: 1006724
Build.VERSION.SDK_INT
tells you the API level that the device runs, which is usually all that a developer will need.
There are other fields on Build.VERSION
that may be of interest to you, if your goal is to display that information to users.
Upvotes: 0
Reputation: 1405
You can check with android.os.Build.VERSION.SDK_INT
To check if device is running Android lollipop or above :
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
// do something
}
Details: https://developer.android.com/reference/android/os/Build.VERSION.html
Upvotes: 0