Android
System Version
Check Android Version
Mobile OS
Android Tutorial

How can I check the system version of Android?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

On Android, the right way to check the system version depends on what you need the value for. If you want runtime branching in app code, use the numeric API level through Build.VERSION.SDK_INT. If you want a human-readable version string for display or logging, use properties such as Build.VERSION.RELEASE.

Use SDK_INT for Logic

For feature checks and compatibility branches, Build.VERSION.SDK_INT is the stable API to use. It returns an integer that maps to Android platform levels.

kotlin
1import android.os.Build
2
3fun isAtLeastAndroid13(): Boolean {
4    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
5}

This is the recommended form because API level comparisons are stable and explicit. They are what the Android framework itself uses for version gating.

Use RELEASE for Display

If you want to show the Android version to the user or log it for diagnostics, Build.VERSION.RELEASE is the usual human-readable string.

kotlin
1import android.os.Build
2
3fun versionLabel(): String {
4    return "Android ${Build.VERSION.RELEASE}"
5}

This is good for status screens and analytics logs, but not ideal for behavior checks because string formatting conventions can vary.

A Complete Kotlin Example

This small example reads both the numeric and display-oriented values.

kotlin
1import android.os.Build
2import android.util.Log
3
4fun logAndroidVersion() {
5    val apiLevel = Build.VERSION.SDK_INT
6    val release = Build.VERSION.RELEASE
7    val codename = Build.VERSION.CODENAME
8
9    Log.d("VersionCheck", "API level: $apiLevel")
10    Log.d("VersionCheck", "Release: $release")
11    Log.d("VersionCheck", "Codename: $codename")
12}

CODENAME is occasionally useful during preview builds, but most production version checks should still rely on SDK_INT.

Java Version of the Same Check

If the project is written in Java, the same APIs are available.

java
1import android.os.Build;
2import android.util.Log;
3
4public class VersionUtils {
5    public static void logVersion() {
6        int apiLevel = Build.VERSION.SDK_INT;
7        String release = Build.VERSION.RELEASE;
8
9        Log.d("VersionCheck", "API level: " + apiLevel);
10        Log.d("VersionCheck", "Release: " + release);
11    }
12}

Nothing about this check requires a Context, which is another reason it is easy to place inside utility code.

Branching for Newer APIs

A common use case is safely calling an API that exists only on newer Android versions.

kotlin
1import android.os.Build
2
3fun maybeUseModernApi() {
4    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
5        println("Safe to use Android 8.0+ API path")
6    } else {
7        println("Use legacy fallback")
8    }
9}

This pattern is much safer than checking version strings manually.

Prefer Feature Detection When Possible

Version checks are useful, but feature detection can be even better when the framework supports it. If a capability is available through a support library or compatibility API, that approach can be more future-proof than direct version branching.

Still, direct version checks remain common and appropriate when the platform behavior truly differs by API level.

Device Model Is a Different Question

Developers sometimes mix up Android system version with device model. These are separate values:

  • Android version means OS version such as API 34 or release string 14
  • device model means hardware identity such as Pixel or Galaxy device name

If you need the hardware model, use fields such as Build.MODEL instead of the version APIs.

Testing Notes

When testing version-dependent code:

  • run on multiple emulator API levels when possible
  • verify the fallback path, not only the newest path
  • keep the check close to the code that actually depends on it

That makes compatibility bugs easier to spot during maintenance.

Common Pitfalls

  • Using Build.VERSION.RELEASE string comparisons for runtime logic.
  • Forgetting that API level and device model are different concepts.
  • Writing version checks when a compatibility library already solves the problem.
  • Burying the check far away from the platform-dependent code path.
  • Testing only on one emulator version and assuming all branches are correct.

Summary

  • Use Build.VERSION.SDK_INT for runtime compatibility checks.
  • Use Build.VERSION.RELEASE for human-readable display or logging.
  • 'Build.VERSION_CODES provides readable constants for API comparisons.'
  • Do not compare version strings when numeric API levels are available.
  • Keep version checks tied to actual platform-dependent behavior, not to general app flow.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.