Wednesday, January 11, 2023
HomeMobileAndroid Builders Weblog: Extending the Android SDK

Android Builders Weblog: Extending the Android SDK



Posted by Anton Hansson, Software program EngineerAndroid 10 and better help Modular System Elements that enable us to expedite practical and safety updates to the Android ecosystem exterior of main API stage releases and make new performance backward suitable on already-released Android variations. These enhancements assist make improvement extra versatile and broaden the attain for app builders. We have constructed a brand new Extension SDK framework so that you can combine with these APIs, and as we speak, we’re releasing the primary public model of the Extension SDK (Extension Stage 4).

Sooner API and have introductions

Being able to introduce new performance exterior of main API stage releases permits quicker improvements. As shared in a earlier put up, starting this 12 months we plan to roll out the preliminary Privateness Sandbox on Android Beta launch to Android 13 gadgets. You can begin utilizing the Extension SDK to combine your options with the AdServices APIs to arrange for restricted manufacturing testing. Be taught extra on how you can take part within the Privateness Sandbox Beta launch, and arrange your improvement setting with a check gadget or emulator.

Backward compatibility

Extension SDKs additionally enable us to increase the help of sure platform performance to current Android variations, rising person attain. For instance, the PhotoPicker APIs beforehand obtainable solely on API stage 33 (Android T) and above at the moment are additionally obtainable all the best way again to API stage 30 (Android R) by means of the Extension SDK on gadgets with an R extension model of no less than 2.
Moving image showing Photopicker API in action on a cellphone screen

Verify for API availability

That can assist you determine extension API availability, we’ve added extra info to the API reference that signifies for which API ranges and the minimal extension variations that the API is obtainable. For instance, the API reference for ACTION_PICK_IMAGES signifies its availability on “Android R Extensions model 2” and above.
Action_Pick_Images link Added in API level 33 Also in R Extensions 2
You may question the extension model at runtime in an identical method to how Construct.VERSION.SDK_INT is usually used to test for the Android model. For instance, if you must confirm the supply of the PhotoPicker APIs, use the brand new API SdkExtensions.getExtensionVersion. For the R extensions, the model code (30) that corresponds to R is used:
enjoyable isPhotoPickerAvailable(): Boolean {
return SdkExtensions.getExtensionVersion(VERSION_CODES.R) >= 2
}

The choice test, by way of Construct.VERSION.SDK_INT, would appear to be this:

enjoyable isPhotoPickerAvailable(): Boolean {
return Construct.VERSION.SDK_INT >= 33
}

This test continues to be protected and proper, however this operate would return false on some gadgets the place the API is now obtainable. Consequently, the SDK_INT test isn’t optimum, and the extension model test is a greater method to test for API availability. All gadgets with SDK_INT >= 33 additionally have an R extension model of >= 2, however there are gadgets with SDK_INT < 33 with R extension variations >= 2.

Equally, the AdServices API reference might point out that it’s “added in Advert Companies Extensions 4”. The Advert Companies extension makes use of the SdkExtensions.AD_SERVICES fixed. The supply test seems like this:

enjoyable isAdServicesAvailable(): Boolean {
return SdkExtensions.getExtensionVersion(SdkExtensions.AD_SERVICES) >= 4
}

For developer comfort, we’re extending Jetpack to make it simpler to work with extension variations. For instance, you should use a Jetpack library operate to test for PhotoPicker availability, which abstracts away the conditional model checks. We count on to be releasing extra Jetpack libraries (such because the Privateness Preserving APIs within the Privateness Sandbox) to help the right use of APIs launched by way of Extension SDKs.

Tooling help

To assist guarantee app high quality, we added Extension variations tooling help to Android Lint’s NewApi test. Since Android Studio Flamingo, it will probably auto-generate the right model checks for APIs which have been launched by way of SDK extensions. Utilizing these new model checks is totally non-compulsory, however adopting them may assist result in extra widespread use of latest APIs once they exist.

Screen grab of version check in use

Get familiarized with SDK extensions

We’re simply starting the SDK Extension developer journey and plan to make extra options obtainable sooner or later. You may get the most recent SDK extension 4 obtainable within the SDK Supervisor as we speak. Be taught extra concerning the SDK Extensions and our documentation on the Privateness Sandbox Beta and the photograph picker.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments