Android 12 Developer preview features

Tram Ho

Android 12 introduces great new features and APIs for developers. The sections below help you learn about features for your application and get started with related APIs.

User experience

Haptic effects combine sound

Apps on Android 12 can generate haptic feedback from the sound with the device’s vibrator, creating a richer gameplay and audio experience. For example, tactile-enhancing ringtones can help identify a caller, or a driving game that can simulate a feeling of rough terrain.

Details please refer to the HapticGenerator documentation.

Rounded APIs

Android 12 introduces RoundedCorner and WindowInsets.getRoundsCorner (int position) , which provide radius and center for rounded corners. With these APIs, your application can avoid truncated UI parts on screens that have rounded corners.

To implement this feature, get RoundedCorner information through WindowInsets.getRoundsCorner (int position) relative to the app’s border. If the app doesn’t take up the entire screen, the API applies the rounded corner by aligning the center point of the rounded corner to the app’s window border.

The following code snippet is a simple example for an application to avoid UI truncation by setting the margins of the view based on information from RoundedCorner . In this case, it is the top right rounded corner.

Improved Immersive mode for gesture navigation

Android 12 simplifies immersive mode to make gesture navigation easier and more consistent with the rest of the experience of actions like watching videos and reading books. Apps can still avoid random gestures during a full-screen gaming experience so that users don’t accidentally exit their game while playing; All other full screen or immersive experiences now allow users to navigate their phone with one swipe.

To do this, the existing behavior for the immersive non-sticky experience ( BEHAVIOR_SHOW_BARS_BY_TOUCH , BEHAVIOR_SHOW_BARS_BY_SWIPE ) started being deprecated in Android 12. They were replaced with the default behavior ( BEHAVIOR_DEFAULT ) that allows one-time gestures. swipe when hiding the system bar. This flag exhibits different visual and functional behavior depending on the mode:

  • In 3-button mode, the visual and functional behavior is an immersive mode in versions prior to Android 12.
  • In gesture navigation mode, works as follows:
    • In terms of visuals, it’s like immersive mode in Android 11 and below.
    • Functionally, gestures are allowed even when the bar is hidden; The back system requires only one swipe to call instead of the two required for Android 11. No extra swipes required to pull down the notification bar or swipe up from the bottom.

Sticky immersive mode ( BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE ) does not change for Android 12. Note the following backward compatibility for this feature:

New experience

Insert rich content

Android 12 introduces a new unified API that lets you get rich content from any available source: clipboard, keyboard, or drag and drop. Details see .

Graphics and images

Supports AVIF format

Android 12 introduces support for images that use the AV1 Image File Format (AVIF). AVIF is the container format for AV1-encoded images and image sequences. It takes advantage of the content encoded in the frame from the video compression process. This significantly improves image quality for the same file size when compared to older image formats, such as JPEG. For a more in-depth look at the pros of this format, check out Jake Archibald’s blog post.

Easier blurring, color filters and other effects

Android 12 adds a new RenderEffect that applies popular graphic effects like blurs, color filters, Android shadow effects, etc. to View and gradation rendering. Effects can be combined as a chain effect (creating an inner and outer effect) or a blending effect. Different Android devices may or may not support this feature due to limited processing power.

The effects can also be applied to the below RenderNode to Views by calling View.setRenderEffect (RenderEffect) .

To implement RenderEffect :

Native animated image decoding

In Android 12, the NDK ImageDecoder API has been extended to decode all frames and timing data from images using animated GIF and WebP file formats . When it was introduced in Android 11, this API only decodes the first image from animations in these formats.

Use ImageDecoder instead of a third-party library to further reduce APK size and benefit from future updates related to security and performance.


Compatible media transcoding

Android 12 can automatically transcode HEVC (H.265) and HDR (HDR10 and HDR10 +) videos recorded on the device to AVC (H.264), a format widely compatible with standard players. This takes advantage of modern codecs as they become available without sacrificing compatibility with older applications.

See the compatible media transcoding section for more details.

MediaDrm updates

To determine if the secure decoder is required with existing MediaDrm APIs, you must follow these steps:

  1. Create MediaDrm .
  2. Open the session to get the session id.
  3. Create MediaCrypto using session id.
  4. Call MediaCrypto.requiresSecureDecoderComponent (mimeType)


Hide application overlay windows

To give developers more control over what users see when they interact with apps, Android 12 introduces the ability to hide overlay windows for apps that have been granted SYSTEM_ALERT_WINDOW permission.

After declaring the HIDE_OVERLAY_WINDOWS permission, an application can call setHideOverlayWindows () to indicate that all windows of type TYPE_APPLICATION_OVERLAY must be hidden when the application’s own window is visible. Apps can choose to do this when displaying sensitive screens, such as transaction confirmation streams.

Apps that display the TYPE_APPLICATION_OVERLAY type window should consider alternatives that may be more appropriate for their use case, such as picture- in -picture or bubbles .

Device attribute authentication

Android 12 expands the set of apps that can verify the device attributes included in a certificate’s certificate when they generate a new key.

As of Android 9 (API level 28), device policy holders (DPOs) using Keymaster 4.0 or higher can verify the device’s properties in these certificates. Starting with Android 12, any application that targets Android 12 can perform this verification using the setDevicePropertiesAttestationIncluded () method .

The generated device properties include the following build fields:


Notification actions on secure lock screen

Android 12 adds a new setAuthenticationRequired flag to Notification.Action.Builder . This flag allows you to add an extra layer of security to the notifications on the locked device.

When this flag is applied with the value true for a certain notification action, the user calling that action on the locked device always results in an authentication request. Previously, the system only required authentication on locked devices when a user called an action announcing that an activity was started or a direct response was called.

To implement this feature, add setAuthenticationRequired to a notification action:


Bandwidth estimation improvements

In Android 12, bandwidth estimation capabilities provided by getLinkDownstreamBandwidthKbps () and getLinkUpstreamBandwidthKbps () are improved for both Wi-Fi and mobile connections. The values ​​returned represent the average full-time carrier weight or WiFi SSID, network type, and signal level across all applications on the device. This makes estimating more accurate and realistic about your application bandwidth.

Keep companion app awake

To support the needs of always-on companion apps for device management, Android 12 introduces APIs that do the following:

  • Allows you to wake up the app when the companion device is in range.
  • Make sure that the process will continue to run while the device is still within range of the device.

To use the API, your devices must be connected using Companion Device Manager . For more information, see CompanionDeviceManager.startObservingDevicePresence () and CompanionDeviceService.onDeviceAppared () .

Here are some of the new features on Android 12 coming soon. Thank you everyone for reading my article

Share the news now

Source : Viblo