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.
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.
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.
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.
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.
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.
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.RELEASEstring 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_INTfor runtime compatibility checks. - Use
Build.VERSION.RELEASEfor human-readable display or logging. - '
Build.VERSION_CODESprovides 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
- How can I check what is stored in my Core Data Database?
- How can I check whether dark mode is enabled in iOS/iPadOS?
- How can I click a button behind a transparent UIView?
- How can I close/hide the Android soft keyboard programmatically?
- How can I color a UIImage in Swift?
- How can I color a UIImage in Swift?
- How can I combine two Dictionary instances in Swift?
- How can I concatenate NSAttributedStrings?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack 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.