How to Get Android SDK Version (API Level) Programmatically
Learn to retrieve Android SDK version and API level programmatically using Build.VERSION.SDK_INT in Java and Kotlin. Includes runtime checks, compatibility table, and best practices for android sdk versions and android api levels.
How to retrieve the Android API version (SDK level) programmatically on a device?
To retrieve the Android API version (also known as the SDK level) programmatically on a device, grab Build.VERSION.SDK_INT from android.os.Build. This integer—say, 34 for Android 14 or 35 for Android 15—lets you check android sdk versions and android api levels at runtime for safe API calls. It’s dead simple, no permissions needed, and works across all devices.
Contents
- What is the Android API Level (SDK Version)?
- Get Android SDK Version in Java
- Kotlin Version for Android API Level
- Device SDK_INT vs CompileSdk and TargetSdk
- Android API Levels Compatibility Table
- Best Practices, Runtime Checks, and Troubleshooting
- Sources
- Conclusion
What is the Android API Level (SDK Version)?
Ever boot up an old phone and wonder why your fancy new feature crashes? That’s the Android API level, or SDK version, in action. It’s an integer that pins down exactly which Android release the device runs—like 33 for Android 13 or 34 for Android 14. Developers obsess over android sdk versions because it dictates what APIs are available at runtime.
Why care? Your app might compile fine against the latest android api levels, but on a grandma’s tablet stuck at API 28 (Android 9), it’ll bomb without checks. The official docs nail it: Build.VERSION.SDK_INT returns this magic number instantly. No network calls, no fuss. Just import android.os.Build and you’re golden.
It’s not the same as your app’s versionCode—that’s for Play Store updates. Here, we’re talking device OS specifics. And yeah, android sdk version 33 or android 13 sdk version? Both point to the same integer check.
Get Android SDK Version in Java
Java devs, this one’s for you. Drop this into any Activity or Service, and it’ll spit out the android sdk version right now.
import android.os.Build;
import android.util.Log;
// Somewhere in your code, like onCreate()
int sdkVersion = Build.VERSION.SDK_INT;
Log.d("SDK Check", "Device runs Android API level: " + sdkVersion);
// Quick runtime check example
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
// Safe for Android 13+ (API 33) – use new features
doModernStuff();
} else {
// Fallback for older **android sdk versions**
doLegacyStuff();
}
See how clean? SDK_INT is an int, so 35 means Android 15 as of early 2026. Test it on an emulator first—fire up Android Studio, pick API 30, run, and watch the logs. Boom, 30.
GeeksforGeeks walks through similar snippets, emphasizing logs for debugging their tutorial. Pro tip: Pair it with Build.VERSION.RELEASE for the string like “14”, but stick to integers for comparisons—they’re reliable.
What if you’re targeting android sdk version 21 (Lollipop)? Same code. Universal.
Kotlin Version for Android API Level
Kotlin’s where most Android work happens now. Shorter, sweeter. Here’s the goods:
import android.os.Build
import android.util.Log
// In your Activity or wherever
val sdkVersion = Build.VERSION.SDK_INT
Log.d("SDK Check", "Running on API level: $sdkVersion")
// Runtime guard – love those when expressions
when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE -> {
// Android 14+ (API 34), go wild
modernFeature()
}
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> {
// Android 13 (API 33) fallback
semiModernFeature()
}
else -> {
// Older **android api levels**, keep it basic
legacyFeature()
}
}
Null-safe? Check. Readable? Absolutely. Kotlin shines here—no semicolons, string interpolation for free. If you’re on android 15 sdk version (API 35), this catches it seamlessly.
Medium posts hammer home why these checks beat blind compiles—runtime reality bites one solid breakdown. Run it in a Fragment? Same deal. Coroutines? Wrap in viewModelScope if async.
Device SDK_INT vs CompileSdk and TargetSdk
Confusion alert: android check sdk version at runtime isn’t your build.gradle settings. Let’s unpack.
- SDK_INT (runtime): Device’s actual API, from
Build.VERSION.SDK_INT. Unchangeable per boot. - compileSdk: Highest API your code compiles against. Bump it to use new stuff in IDE.
- targetSdk: What Google Play thinks your app optimizes for. Affects behaviors like permissions.
Mix them up, and crashes happen. Say you compileSdk 34 but run on android sdk version 33—boom, unless you check SDK_INT. Wikipedia’s history page maps these forever Android version history.
android min sdk version in your manifest? That’s the floor—no installs below it. But runtime? Always verify.
Quick table for clarity:
| Setting | Purpose | Example (2026) |
|---|---|---|
| SDK_INT | Device runtime level | 35 (Android 15) |
| compileSdk | Compile-time APIs | 35 |
| targetSdk | Behavior adaptation | 34 |
| minSdk | Install barrier | 24 (Android 7) |
Nail this, avoid half your bugs.
Android API Levels Compatibility Table
Need android sdk versions at a glance? Here’s the rundown up to today (January 2026). Pulled from official mappings.
| Android Version | API Level (SDK_INT) | Codename | Notes |
|---|---|---|---|
| Android 15 | 35 | VanillaIceCream | Latest stable |
| Android 14 | 34 | UpsideDownCake | QPR updates ongoing |
| Android 13 | 33 | Tiramisu | Common in 2026 fleets |
| Android 12L | 32 | SnowCone v2 | Tablets |
| Android 12 | 31 | SnowCone | Material You debut |
| Android 11 | 30 | Red Velvet Cake | Scoped storage |
| Android 10 | 29 | - | Dark theme |
| Android 9 | 28 | Pie | Gestures |
| Android 8.1 | 27 | - | Project Treble |
| Android 7.0 | 24 | Nougat | android 7 sdk version baseline for many |
Check against Wikipedia for full history. Use like: if (SDK_INT >= 33) { /* Tiramisu+ */ }. Covers android 13 sdk version searches perfectly.
Best Practices, Runtime Checks, and Troubleshooting
Don’t just grab the number—use it smart.
- Always compare constants:
Build.VERSION_CODES.O> magic numbers. Future-proofs. - Gradle sync: Keep compileSdk fresh, but check runtime.
- Emulator testing: Spin up API 21-35, verify logs.
- Edge cases: Wear OS? Same API. Custom ROMs? Rarely off.
Trouble? Log shows wrong number? Reboot device—rare kernel glitch. Permissions? None needed. Crashes on old android api levels? Add @RequiresApi annotations for Lint help.
FAQ-style: How to get version code android too? PackageManager for app version:
val pm = packageManager
val info = pm.getPackageInfo(packageName, 0)
val versionCode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
info.longVersionCode
} else {
@Suppress("DEPRECATION")
info.versionCode.toLong()
}
Boom. Covers android version code version name queries.
Stack Overflow vibes? Nah, this is tighter. Questions like “android 14 sdk version”? It’s 34—check the table.
Sources
- Android Developers - Build.VERSION
- GeeksforGeeks - How to Get the Build Version Number
- Wikipedia - Android version history
- Medium - minSdk, targetSdk, and compileSdk
Conclusion
Retrieving the Android API version boils down to one line: Build.VERSION.SDK_INT. Master runtime checks with Build.VERSION_CODES, test across android sdk versions, and your app stays bulletproof from API 21 to 35+. Skip the guesswork—implement today, ship confidently. Questions? Drop 'em in comments.