How can I check the system version of Android?
Does anyone know how can I check the system version (e.g. 1.0
, 2.2
, etc.) programatically?
Example how to use it:
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD) {
// only for gingerbread and newer versions
}
Check android.os.Build.VERSION
.
CODENAME
: The current development codename, or the string "REL" if this is a release build.INCREMENTAL
: The internal value used by the underlying source control to represent this build.RELEASE
: The user-visible version string.
Build.Version is the place go to for this data. Here is a code snippet for how to format it.
public String getAndroidVersion() {
String release = Build.VERSION.RELEASE;
int sdkVersion = Build.VERSION.SDK_INT;
return "Android SDK: " + sdkVersion + " (" + release +")";
}
Looks like this "Android SDK: 19 (4.4.4)"
For checking device version which is greater than or equal to Marshmallow ,use this code.
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M){
}
for ckecking others just change the VERSION_CODES like,
K for kitkat,
L for loolipop
N for Nougat and so on...
Build.VERSION.RELEASE;
That will give you the actual numbers of your version; aka 2.3.3 or 2.2. The problem with using Build.VERSION.SDK_INT is if you have a rooted phone or custom rom, you could have a none standard OS (aka my android is running 2.3.5) and that will return a null when using Build.VERSION.SDK_INT so Build.VERSION.RELEASE will work no matter what!