Understanding Android API Levels

This article provides brief information on Android API Levels and related details on the same.

Ted Blair Omino
Make Android
3 min readJul 8, 2023

--

Android API/Version levels

Hi, there Android devs, and welcome to this article on Android API levels. Understanding API levels is important to ensure app compatibility while leveraging new features and capabilities ensuring a nice user experience.

API levels are numerical values that represent a version of the Android platform. Targeting the correct API level allows you to tap into the latest features of that API while ensuring compatibility with older versions. Each successive API level may offer updates on previous features offered by older versions. Previous features are not necessarily deleted but are deprecated and can still be used although in some instances parts of the API are removed or updated.

Each API level corresponds to a specific Android platform version. The newest API level is 34 and has come a long way from API level 1. The Android versions, API levels, and Version codes are shown in the table below:

Because most API level features are mostly updates, Android applications developed at any API level are forward_compatible which means they can leverage features of future API levels.

Importance of targeting API levels

  1. Compatibility across devices: selecting the min API level for your app ensures it runs on a wide range of devices. It also ensures your app is not installed on version-incompatible devices.
  2. New features: each API level provides new enhancements and security safeguards that can be used to provide a better app user experience.
  3. Compatibility with Third-Party Libraries: Some third-party libraries work only at specific API levels.

Your application’s API level is usually defined in the build.gradle file as shown in the picture below:

build.gradle(Module) file

The attributes used to define the API levels are:

  • minSdkVersion: This is the minimum API level your app will support. As shown in the image above, the minimum SDK is 24 hence the application will run on devices with Android 7 and above.
  • targetSdkVersion: This is the API level that your application can run on. This should be similar to the compiledSDK.

To get the SDK of the user device at run time, you can use Build.VERSION.SDK_INT. This way you can target devices of a specific API level that need a feature that is important at that API level in an activity or fragment. The code below shows how to create a notification channel for devices with API level 26+(Android Oreo):

private fun createNotificationChannel(){
//creates a notification channel for API level 26+ because it is new
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){
val channel=NotificationChannel(CHANNEL_ID, getString(R.string.app_name),NotificationManager.IMPORTANCE_DEFAULT)
channel.description="Notification channel"

val notificationManager=getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
}
}

This is just one of the many reasons why understanding API levels in Android is important. Proper targeting of API levels will prevent installation of an app in a device that is not supported which will cause it to subsequently crash.

In conclusion, understanding Android API levels is crucial for ensuring app compatibility, and leveraging new features. By targeting the appropriate API level, you can tap into the latest enhancements while maintaining compatibility with older versions of Android.

In addition, understanding how to target specific API levels at runtime enables you to incorporate features that may be available only on certain API levels. This ensures that your app functions correctly on devices that require specific features or behaviors.

Explore the official Android documentation on updates that come with the various APIs and learn them to stay ahead of the curve. Happy coding!

--

--