09 January 2023
Posted by Anton Hansson, Software EngineerAndroid 10 and higher support Modular System Components that allow us to expedite functional and security updates to the Android ecosystem outside of major API level releases and make new functionality backward compatible on already-released Android versions. These improvements help make development more flexible and broaden the reach for app developers. We've built a new Extension SDK framework for you to integrate with these APIs, and today, we’re releasing the first public version of the Extension SDK (Extension Level 4).
Having the ability to introduce new functionality outside of major API level releases allows faster innovations. As shared in a previous post, beginning this year we plan to roll out the initial Privacy Sandbox on Android Beta release to Android 13 devices. You can start using the Extension SDK to integrate your solutions with the AdServices APIs to prepare for limited production testing. Learn more on how to participate in the Privacy Sandbox Beta release, and set up your development environment with a test device or emulator.
fun isPhotoPickerAvailable(): Boolean {
return SdkExtensions.getExtensionVersion(VERSION_CODES.R) >= 2
}
|
The alternative check, via Build.VERSION.SDK_INT, would look like this:
fun isPhotoPickerAvailable(): Boolean {
return Build.VERSION.SDK_INT >= 33
}
|
This check is still safe and correct, but this function would return false on some devices where the API is now available. As a result, the SDK_INT check is not optimal, and the extension version check is a better way to check for API availability. All devices with SDK_INT >= 33 also have an R extension version of
>= 2, but there are devices with SDK_INT < 33 with R extension versions >= 2.
Similarly, the AdServices API reference may indicate that it’s “added in Ad Services Extensions 4”. The Ad Services extension uses the SdkExtensions.AD_SERVICES constant. The availability check looks like this:
fun isAdServicesAvailable(): Boolean {
return SdkExtensions.getExtensionVersion(SdkExtensions.AD_SERVICES) >= 4
} |
For developer convenience, we are extending Jetpack to make it easier to work with extension versions. For example, you can use a Jetpack library function to check for PhotoPicker availability, which abstracts away the conditional version checks. We expect to be releasing more Jetpack libraries (such as the Privacy Preserving APIs in the Privacy Sandbox) to aid the correct use of APIs released via Extension SDKs.
We’re just beginning the SDK Extension developer journey and plan to make more features available in the future. You can get the latest SDK extension 4 available in the SDK Manager today. Learn more about the SDK Extensions and our documentation on the Privacy Sandbox Beta and the photo picker.