Get Android API level of phone currently running my application
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
If you need the Android API level of the device currently running your app, the standard answer is Build.VERSION.SDK_INT. That integer tells you which Android API level is available at runtime, so you can gate newer functionality safely.
This matters because Android version names are not enough for code decisions. Runtime compatibility checks should be based on API levels or feature detection.
Use Build.VERSION.SDK_INT
In Kotlin, the usual runtime check looks like this:
In Java, the equivalent is:
This is the value you compare against Build.VERSION_CODES constants.
Compare Against Named Version Constants
Hard-coding raw numbers works, but named constants are clearer and safer.
This makes the intent obvious when you revisit the code later.
API Level Checks Versus Feature Checks
API level checks are useful when the platform method or behavior truly appeared in a known Android release. But if the question is whether hardware or a service is present, feature detection is often better.
For example, checking camera support or biometric capability should usually rely on the relevant package manager or library API, not only on SDK_INT. The platform version and the actual device capability are related, but they are not identical.
Use API Checks to Guard Code Paths
A common use case is choosing different code paths for newer and older Android versions. That should happen at the point where behavior diverges.
Keeping the check close to the version-sensitive code makes maintenance easier than computing the API level once and passing it everywhere.
Runtime API Level Is Not the Same as minSdk or targetSdk
Another source of confusion is mixing runtime API level with build configuration values. minSdk describes the oldest version your app claims to support, and targetSdk describes the platform level you are targeting during development. Neither of those tells you what device version the current user is actually running. For runtime decisions, Build.VERSION.SDK_INT is the value that matters.
That distinction becomes important when debugging device-specific bugs. Two builds with the same targetSdk can still behave differently because they are running on devices with different runtime API levels.
If you log version information in crash reports or analytics, include SDK_INT rather than only the Android marketing version name. The integer is what the code paths actually use.
That makes production debugging easier when behavior differs between devices that look similar to end users.
Common Pitfalls
- Using Android version marketing names instead of
SDK_INTin code decisions. - Hard-coding raw numbers when
Build.VERSION_CODESis clearer. - Using API-level checks where feature detection would be more correct.
- Forgetting that compile-time availability and runtime availability are different issues.
- Reading old examples that use deprecated version fields instead of
SDK_INT.
Summary
- Use
Build.VERSION.SDK_INTto get the current device API level. - Compare it against
Build.VERSION_CODESwhen gating version-specific behavior. - Keep checks close to the code path they protect.
- Prefer feature detection when the real question is device capability rather than platform version.
- Avoid older deprecated version fields in new Android code.
Related reading
- Get detailed error messages from AWS API Gateway Request Validator
- get ec2 pricing programmatically?
- Get Errno 48 while using Pub-Sub ZeroMQ sockets with a specific IP address other than localhost
- Get error unknown field serviceName in io.k8s.api.networking.v1.IngressBackend when switch from v1beta1 to v1 in Kubernetes Ingress
- Get Android .apk file VersionName or VersionCode WITHOUT installing apk
- Get Android Device Name
- Get filename and path from URI from mediastore
- Get hosted zone for cloudfront distribution

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.