Tổng quan về các tính năng và API

Android 14 mang đến cho nhà phát triển các tính năng và API tuyệt vời. Nội dung sau đây giúp bạn tìm hiểu các tính năng cho ứng dụng cũng như làm quen với các API liên quan.

Để biết danh sách chi tiết về các API đã thêm, sửa đổi và xoá, hãy đọc báo cáo điểm khác biệt về API. Để biết thông tin chi tiết về các API đã thêm, hãy truy cập vào tài liệu tham khảo về API Android. Đối với Android 14, hãy tìm các API đã thêm trong API cấp 34. Để tìm hiểu những thay đổi của nền tảng có thể tác động đến ứng dụng của bạn, hãy nhớ tham khảo các thay đổi về hành vi của Android 14 đối với ứng dụng nhắm đến Android 14tất cả ứng dụng.

Quốc tế hoá

Lựa chọn ưu tiên về ngôn ngữ cho mỗi ứng dụng

Android 14 expands on the per-app language features that were introduced in Android 13 (API level 33) with these additional capabilities:

  • Automatically generate an app's localeConfig: Starting with Android Studio Giraffe Canary 7 and AGP 8.1.0-alpha07, you can configure your app to support per-app language preferences automatically. Based on your project resources, the Android Gradle plugin generates the LocaleConfig file and adds a reference to it in the final manifest file, so you no longer have to create or update the file manually. AGP uses the resources in the res folders of your app modules and any library module dependencies to determine the locales to include in the LocaleConfig file.

  • Dynamic updates for an app's localeConfig: Use the setOverrideLocaleConfig() and getOverrideLocaleConfig() methods in LocaleManager to dynamically update your app's list of supported languages in the device's system settings. Use this flexibility to customize the list of supported languages per region, run A/B experiments, or provide an updated list of locales if your app utilizes server-side pushes for localization.

  • App language visibility for input method editors (IMEs): IMEs can utilize the getApplicationLocales() method to check the language of the current app and match the IME language to that language.

API Biến tố ngữ pháp

Có đến 3 tỷ người sử dụng ngôn ngữ có phân biệt giống ngữ pháp: ngôn ngữ mà các danh mục ngữ pháp (chẳng hạn như danh từ, động từ, tính từ và giới từ) sẽ phản ánh theo giống của người và đối tượng mà bạn nói đến hoặc nói về. Theo truyền thống, nhiều ngôn ngữ có phân biệt giống ngữ pháp sử dụng giống đực làm giống mặc định hoặc chung.

Việc xưng hô sai ngữ pháp với người dùng, chẳng hạn như xưng hô với phụ nữ theo ngữ pháp giống đực, có thể ảnh hưởng tiêu cực đến hiệu suất và thái độ của họ. Ngược lại, giao diện người dùng có ngôn ngữ phản ánh chính xác giống ngữ pháp của người dùng có thể cải thiện mức độ tương tác, cũng như mang lại trải nghiệm tự nhiên và phù hợp hơn cho người dùng.

To help you build a user-centric UI for gendered languages, Android 14 introduces the Grammatical Inflection API, which lets you add support for grammatical gender without refactoring your app.

Lựa chọn ưu tiên theo khu vực

用户可通过地区偏好设置对温度单位、一周的第一天和编号系统进行个性化设置。居住在美国的欧洲用户可能更希望使用摄氏度,而不是华氏度,并且希望应用将星期一视为一周的开始,而不是像美国那样默认从星期日开始。

新 Android 设置菜单包含这些偏好设置,使用户能够在一个位置集中发现这些应用更改偏好设置。这些偏好设置在备份和恢复设备后也会保持不变。多个 API 和 intent(例如 getTemperatureUnitgetFirstDayOfWeek)会为您的应用授予读取权限来访问用户偏好设置,因此您的应用可以调整其显示信息的方式。您还可以在 ACTION_LOCALE_CHANGED 上注册 BroadcastReceiver,以便在地区偏好设置发生更改时处理语言区域配置更改。

如需找到这些设置,请打开“设置”应用,然后依次前往系统 > 语言和输入法 > 地区偏好设置

Android 系统设置中的地区偏好设置界面。
Android 系统中地区偏好设置的温度选项 设置。

Hỗ trợ tiếp cận

Điều chỉnh tỷ lệ phông chữ phi tuyến tính lên đến 200%

Starting in Android 14, the system supports font scaling up to 200%, providing low-vision users with additional accessibility options that align with Web Content Accessibility Guidelines (WCAG).

To prevent large text elements on screen from scaling too large, the system applies a nonlinear scaling curve. This scaling strategy means that large text doesn't scale at the same rate as smaller text. Nonlinear font scaling helps preserve the proportional hierarchy between elements of different sizes while mitigating issues with linear text scaling at high degrees (such as text being cut off or text that becomes harder to read due to an extremely large display sizes).

Test your app with nonlinear font scaling

Enable the maximum font size in a device's accessibility settings to test your app.

If you already use scaled pixels (sp) units to define text sizing, then these additional options and scaling improvements are applied automatically to the text in your app. However, you should still perform UI testing with the maximum font size enabled (200%) to ensure that your app applies the font sizes correctly and can accommodate larger font sizes without impacting usability.

To enable 200% font size, follow these steps:

  1. Open the Settings app and navigate to Accessibility > Display size and text.
  2. For the Font size option, tap the plus (+) icon until the maximum font size setting is enabled, as shown in the image that accompanies this section.

Use scaled pixel (sp) units for text-sizes

Remember to always specify text sizes in sp units. When your app uses sp units, Android can apply the user's preferred text size and scale it appropriately.

Don't use sp units for padding or define view heights assuming implicit padding: with nonlinear font scaling sp dimensions might not be proportional, so 4sp + 20sp might not equal 24sp.

Convert scaled pixel (sp) units

Use TypedValue.applyDimension() to convert from sp units to pixels, and use TypedValue.deriveDimension() to convert pixels to sp. These methods apply the appropriate nonlinear scaling curve automatically.

Avoid hardcoding equations using Configuration.fontScale or DisplayMetrics.scaledDensity. Because font scaling is nonlinear, the scaledDensity field is no longer accurate. The fontScale field should be used for informational purposes only because fonts are no longer scaled with a single scalar value.

Use sp units for lineHeight

Always define android:lineHeight using sp units instead of dp, so the line height scales along with your text. Otherwise, if your text is sp but your lineHeight is in dp or px, it doesn't scale and looks cramped. TextView automatically corrects the lineHeight so that your intended proportions are preserved, but only if both textSize and lineHeight are defined in sp units.

Máy ảnh và nội dung nghe nhìn

Ultra HDR cho hình ảnh

标准动态范围 (SDR) 与高动态范围 (HDR) 图片质量对比示意图。

Android 14 新增了对高动态范围 (HDR) 图片的支持,可在拍摄照片时保留更多来自传感器的信息,从而实现鲜艳的色彩和更高的对比度。Android 使用 Ultra HDR 格式,该格式与 JPEG 图片完全向后兼容,可让应用与 HDR 图片无缝互操作,并根据需要以标准动态范围 (SDR) 显示这些图片。

当您的应用选择为其 activity 窗口使用 HDR 界面(通过清单条目或通过在运行时调用 Window.setColorMode())时,框架会自动在界面中以 HDR 格式渲染这些图片。您还可以在受支持的设备上拍摄压缩的 Ultra HDR 静态图片。从传感器中恢复的颜色越多,后期编辑的灵活性就越高。与 Ultra HDR 图片关联的 Gainmap 可用于使用 OpenGL 或 Vulkan 渲染这些图片。

Thu phóng, Lấy nét, Xem sau và nhiều tính năng khác trong tiện ích máy ảnh

Android 14 upgrades and improves camera extensions, allowing apps to handle longer processing times, which enables improved images using compute-intensive algorithms like low-light photography on supported devices. These features give users an even more robust experience when using camera extension capabilities. Examples of these improvements include:

Thu phóng trong cảm biến

When REQUEST_AVAILABLE_CAPABILITIES_STREAM_USE_CASE in CameraCharacteristics contains SCALER_AVAILABLE_STREAM_USE_CASES_CROPPED_RAW, your app can use advanced sensor capabilities to give a cropped RAW stream the same pixels as the full field of view by using a CaptureRequest with a RAW target that has stream use case set to CameraMetadata.SCALER_AVAILABLE_STREAM_USE_CASES_CROPPED_RAW. By implementing the request override controls, the updated camera gives users zoom control even before other camera controls are ready.

Âm thanh USB không bị mất dữ liệu

Android 14 hỗ trợ các định dạng âm thanh không suy hao để mang lại trải nghiệm âm thanh chất lượng cao qua tai nghe có dây USB. Bạn có thể truy vấn một thiết bị USB để biết các thuộc tính bộ trộn ưu tiên, đăng ký trình nghe cho các thay đổi trong các thuộc tính bộ trộn ưu tiên và định cấu hình các thuộc tính bộ trộn bằng cách sử dụng lớp AudioMixerAttributes. Lớp này đại diện cho định dạng, chẳng hạn như mặt nạ kênh, tốc độ lấy mẫu và hành vi của bộ trộn âm thanh. Lớp này cho phép gửi trực tiếp âm thanh mà không cần trộn, điều chỉnh âm lượng hoặc xử lý hiệu ứng.

Công cụ và năng suất của nhà phát triển

Trình quản lý thông tin xác thực

Android 14 将 Credential Manager 添加为平台 API,并通过使用 Google Play 服务的 Jetpack 库,向后额外支持 Android 4.4(API 级别 19)设备。Credential Manager 旨在通过 API 使用用户配置的凭据提供程序检索和存储凭据,让用户更轻松地登录。Credential Manager 在单个 API 中支持多种登录方法,包括用户名和密码、通行密钥和联合登录解决方案(如“使用 Google 账号登录”)。

通行密钥具有许多优势。例如,通行密钥是基于业界标准构建的,可在各种不同的操作系统和浏览器生态系统中使用,并且可用于网站和应用。

如需了解详情,请参阅 Credential Manager 和通行密钥文档以及介绍 Credential Manager 和通行密钥的博文

Health Connect

Health Connect là một kho lưu trữ trên thiết bị dành cho dữ liệu sức khoẻ và thể chất của người dùng. Tính năng này cho phép người dùng chia sẻ dữ liệu giữa các ứng dụng mà họ yêu thích, với một nơi duy nhất để kiểm soát dữ liệu họ muốn chia sẻ với các ứng dụng này.

Trên các thiết bị chạy phiên bản Android trước Android 14, bạn có thể tải Health Connect xuống dưới dạng ứng dụng trên Cửa hàng Google Play. Kể từ Android 14, Health Connect là một phần của nền tảng và nhận được bản cập nhật thông qua bản cập nhật hệ thống của Google Play mà không cần tải xuống riêng. Nhờ đó, Health Connect có thể được cập nhật thường xuyên và các ứng dụng của bạn có thể dựa vào Health Connect có sẵn trên các thiết bị chạy Android 14 trở lên. Người dùng có thể truy cập vào Health Connect từ phần Cài đặt trong thiết bị của họ, với các chế độ kiểm soát quyền riêng tư được tích hợp vào phần cài đặt hệ thống.

Người dùng có thể bắt đầu sử dụng Health Connect mà không cần tải ứng dụng riêng xuống trên các thiết bị chạy Android 14 trở lên.
Người dùng có thể kiểm soát những ứng dụng có quyền truy cập vào dữ liệu sức khoẻ và thể chất của họ thông qua phần cài đặt hệ thống.

Health Connect có một số tính năng mới trong Android 14, chẳng hạn như tuyến đường tập thể dục, cho phép người dùng chia sẻ tuyến đường tập thể dục của họ và có thể được trực quan hoá trên bản đồ. Tuyến đường được xác định là danh sách các vị trí được lưu trong một khoảng thời gian và ứng dụng của bạn có thể chèn các tuyến đường vào các phiên tập thể dục, liên kết các tuyến đường đó với nhau. Để đảm bảo người dùng có toàn quyền kiểm soát dữ liệu nhạy cảm này, người dùng phải cho phép chia sẻ từng tuyến đường với các ứng dụng khác.

Để biết thêm thông tin, hãy xem tài liệu về Health Connect và bài đăng trên blog về Tính năng mới trong Android Health.

Nội dung cập nhật OpenJDK 17

Android 14 tiếp tục công cuộc làm mới các thư viện cốt lõi của Android để phù hợp với các tính năng trong bản phát hành OpenJDK LTS mới nhất, bao gồm cả bản cập nhật thư viện và tính năng hỗ trợ ngôn ngữ Java 17 cho các nhà phát triển ứng dụng và nền tảng.

Bao gồm các tính năng và điểm cải tiến sau đây:

  • Cập nhật tính năng hỗ trợ Java 17 cho khoảng 300 lớp java.base.
  • Khối văn bản (Text Blocks) ra mắt các giá trị cố định dạng chuỗi nhiều dòng bằng ngôn ngữ lập trình Java.
  • So khớp mẫu cho instanceof, cho phép một đối tượng được xem là có một kiểu cụ thể trong instanceof mà không cần thêm bất cứ biến nào.
  • Lớp kín (sealed classes) cho phép bạn hạn chế các lớp và giao diện có thể mở rộng hoặc triển khai các lớp đó.

Nhờ các bản cập nhật hệ thống Google Play (Project Mainline), hơn 600 triệu thiết bị được phép nhận các bản cập nhật Android Runtime (ART) mới nhất có các thay đổi này. Đây là một phần trong cam kết của chúng tôi nhằm cung cấp cho các ứng dụng một môi trường nhất quán, bảo mật hơn trên các thiết bị, đồng thời cung cấp các tính năng và chức năng mới cho người dùng độc lập với các bản phát hành nền tảng.

Java và OpenJDK là các nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.

Những điểm cải tiến cho cửa hàng ứng dụng

Android 14 引入了多个 PackageInstaller API,可帮助应用商店改善其用户体验。

下载之前请求批准安装

安装或更新应用可能需要用户批准。例如,当使用 REQUEST_INSTALL_PACKAGES 权限的安装程序尝试安装新应用时。在之前的 Android 版本中,只有在将 APK 写入安装会话并且提交会话后,应用商店才能请求用户批准。

从 Android 14 开始,requestUserPreapproval() 方法可让安装程序在提交安装会话之前请求用户批准。此项改进可让应用商店将任何 APK 的下载操作推迟到用户批准安装之后。此外,用户批准安装后,应用商店可以在后台下载并安装应用,而不会干扰用户。

承担未来更新的责任

借助 setRequestUpdateOwnership() 方法,安装程序可以向系统表明它打算负责将被安装的应用未来的更新。此 capability 可实现更新所有权强制执行,即仅允许更新所有者为应用安装自动更新。更新所有权强制执行有助于确保用户仅收到来自预期应用商店的更新。

任何其他安装程序(包括使用 INSTALL_PACKAGES 权限的安装程序)都必须获得用户的明确批准,才能安装更新。如果用户决定继续从其他来源安装更新,则会失去更新所有权。

在干扰较少的时段更新应用

应用商店通常希望避免更新正在使用的应用,因为这会导致应用正在运行的进程被终止,而这可能会中断用户正在执行的操作。

从 Android 14 开始,InstallConstraints API 让安装程序可以确保其应用更新在适当的时机进行。例如,应用商店可以调用 commitSessionAfterInstallConstraintsAreMet() 方法来确保仅在用户不再与相应应用互动时才进行更新。

无缝安装可选拆分

借助拆分 APK,应用的功能可以通过单独的 APK 文件提供,而不是以单体式 APK 的形式提供。借助拆分 APK,应用商店可以优化不同应用组件的提供。例如,应用商店可能会根据目标设备的属性进行优化。自在 API 级别 22 中引入以来,PackageInstaller API 一直支持拆分。

在 Android 14 中,setDontKillApp() 方法可让安装程序指明在安装新的拆分项时应用的运行进程不应终止。应用商店可以使用此功能,在用户使用应用时无缝安装应用的新功能。

Gói siêu dữ liệu ứng dụng

Starting in Android 14, the Android package installer lets you specify app metadata, such as data safety practices, to include on app store pages such as Google Play.

Phát hiện thời điểm người dùng chụp ảnh màn hình thiết bị

To create a more standardized experience for detecting screenshots, Android 14 introduces a privacy-preserving screenshot detection API. This API lets apps register callbacks on a per-activity basis. These callbacks are invoked, and the user is notified, when the user takes a screenshot while that activity is visible.

Trải nghiệm người dùng

Các thao tác tuỳ chỉnh trên Trang chia sẻ nội dung và cách cải thiện thứ hạng

Android 14 cập nhật trang chia sẻ nội dung của hệ thống để hỗ trợ các thao tác tuỳ chỉnh trong ứng dụng và các kết quả xem trước giàu thông tin hơn cho người dùng.

Thêm thao tác tuỳ chỉnh

Với Android 14, ứng dụng của bạn có thể thêm thao tác tuỳ chỉnh vào trang chia sẻ nội dung hệ thống mà ứng dụng đó gọi.

Ảnh chụp màn hình các thao tác tuỳ chỉnh trên trang chia sẻ.

Cải thiện thứ hạng của mục tiêu Chia sẻ trực tiếp

Android 14 sử dụng thêm nhiều tín hiệu từ các ứng dụng để xác định thứ hạng của mục tiêu chia sẻ trực tiếp nhằm đưa ra kết quả hữu ích hơn cho người dùng. Để cung cấp tín hiệu hữu ích nhất cho việc xếp hạng, hãy làm theo hướng dẫn để cải thiện thứ hạng của mục tiêu Chia sẻ trực tiếp. Ứng dụng liên lạc cũng có thể báo cáo mức sử dụng phím tắt cho tin nhắn đến và đi.

Hàng Chia sẻ trực tiếp trong trang chia sẻ nội dung, như minh hoạ bằng 1

Hỗ trợ ảnh động tích hợp sẵn và ảnh động tuỳ chỉnh cho tính năng Xem trước thao tác quay lại

Video: Predictive back animations

Android 13 introduced the predictive back-to-home animation behind a developer option. When used in a supported app with the developer option enabled, swiping back shows an animation indicating that the back gesture exits the app back to the home screen.

Android 14 includes multiple improvements and new guidance for Predictive Back:

With this Android 14 preview release, all features of Predictive Back remain behind a developer option. See the developer guide to migrate your app to predictive back, as well as the developer guide to creating custom in-app transitions.

Chế độ ghi đè cho mỗi ứng dụng của nhà sản xuất thiết bị có màn hình lớn

Per-app overrides enable device manufacturers to change the behavior of apps on large screen devices. For example, the FORCE_RESIZE_APP override instructs the system to resize the app to fit display dimensions (avoiding size compatibility mode) even if resizeableActivity="false" is set in the app manifest.

Overrides are intended to improve the user experience on large screens.

New manifest properties enable you to disable some device manufacturer overrides for your app.

Ghi đè cho mỗi ứng dụng dành cho người dùng màn hình lớn

Tính năng ghi đè cho mỗi ứng dụng thay đổi hành vi của ứng dụng trên thiết bị có màn hình lớn. Ví dụ: chế độ ghi đè của nhà sản xuất thiết bị OVERRIDE_MIN_ASPECT_RATIO_LARGE đặt tỷ lệ khung hình của ứng dụng thành 16:9 bất kể cấu hình của ứng dụng.

Android 14 QPR1 cho phép người dùng áp dụng chế độ ghi đè cho mỗi ứng dụng thông qua trình đơn cài đặt mới trên các thiết bị có màn hình lớn.

Chia sẻ màn hình ứng dụng

借助应用界面共享功能,用户可以在录制屏幕内容时共享应用窗口,而不是整个设备屏幕。

在应用屏幕共享模式下,状态栏、导航栏、通知和其他系统界面元素会从共享显示屏中排除。系统只会分享所选应用的内容。

应用屏幕共享功能可让用户运行多个应用,但将内容共享限制为单个应用,从而提高工作效率并保护隐私。

Tính năng Trả lời thông minh dựa trên LLM trong Gboard trên Pixel 8 Pro

Trên các thiết bị Pixel 8 Pro có Bản phát hành tính năng tháng 12, nhà phát triển có thể dùng thử tính năng trả lời thông minh chất lượng cao hơn trong Gboard nhờ các Mô hình ngôn ngữ lớn (LLM) trên thiết bị chạy trên Google Tensor.

Tính năng này được cung cấp dưới dạng bản dùng thử có giới hạn cho tiếng Anh (Hoa Kỳ) trong WhatsApp, Line và KakaoTalk. Bạn cần sử dụng thiết bị Pixel 8 Pro có Gboard làm bàn phím.

Để dùng thử, trước tiên, hãy bật tính năng này trong phần Settings > Developer Options > AiCore Settings > Enable Aicore Persistent (Cài đặt > Tuỳ chọn cho nhà phát triển > Cài đặt AICore > Bật Aicore Persistent).

Tiếp theo, hãy mở một cuộc trò chuyện trong một ứng dụng được hỗ trợ để xem tính năng Trả lời thông minh dựa trên LLM trong dải đề xuất của Gboard để phản hồi tin nhắn đến.

Gboard sử dụng LLM trên thiết bị để cung cấp tính năng phản hồi thông minh chất lượng cao hơn.

Đồ hoạ

Đường dẫn có thể truy vấn và nội suy

Android 的 Path API 是一种强大且灵活的机制,可用于创建和渲染矢量图形,能够描边或填充路径、根据线段或二次曲线或立方曲线构建路径、执行布尔运算以获取更复杂的形状,或同时执行所有这些操作。但有一个限制是,您无法了解 Path 对象中实际包含的内容;该对象的内部信息在创建后对调用方是不透明的。

如需创建 Path,您可以调用 moveTo()lineTo()cubicTo() 等方法来添加路径段。但是,无法询问该路径有哪些片段,因此您必须在创建时保留该信息。

从 Android 14 开始,您可以查询路径以了解其内部内容。首先,您需要使用 Path.getPathIterator API 获取 PathIterator 对象:

Kotlin

val path = Path().apply {
    moveTo(1.0f, 1.0f)
    lineTo(2.0f, 2.0f)
    close()
}
val pathIterator = path.pathIterator

Java

Path path = new Path();
path.moveTo(1.0F, 1.0F);
path.lineTo(2.0F, 2.0F);
path.close();
PathIterator pathIterator = path.getPathIterator();

接下来,您可以调用 PathIterator 逐个遍历片段,并检索每个片段的所有必要数据。以下示例使用了 PathIterator.Segment 对象,它会为您打包数据:

Kotlin

for (segment in pathIterator) {
    println("segment: ${segment.verb}, ${segment.points}")
}

Java

while (pathIterator.hasNext()) {
    PathIterator.Segment segment = pathIterator.next();
    Log.i(LOG_TAG, "segment: " + segment.getVerb() + ", " + segment.getPoints());
}

PathIterator 还有一个非分配版 next(),您可以在其中传入缓冲区来保存点数据。

查询 Path 数据的一个重要用例是插值。例如,您可能想在两个不同的路径之间添加动画(或变形)。为了进一步简化该用例,Android 14 针对 Path 还包含 interpolate() 方法。假设两个路径具有相同的内部结构,interpolate() 方法会使用该插值结果创建一个新的 Path。以下示例返回了一个形状介于 pathotherPath 之间的一半(线性插值为 0.5)的路径:

Kotlin

val interpolatedResult = Path()
if (path.isInterpolatable(otherPath)) {
    path.interpolate(otherPath, .5f, interpolatedResult)
}

Java

Path interpolatedResult = new Path();
if (path.isInterpolatable(otherPath)) {
    path.interpolate(otherPath, 0.5F, interpolatedResult);
}

Jetpack graphics-path 库也为早期版本的 Android 启用了类似的 API。

Lưới tuỳ chỉnh với chương trình đổ bóng đỉnh và mảnh

Android has long supported drawing triangle meshes with custom shading, but the input mesh format has been limited to a few predefined attribute combinations. Android 14 adds support for custom meshes, which can be defined as triangles or triangle strips, and can, optionally, be indexed. These meshes are specified with custom attributes, vertex strides, varying, and vertex and fragment shaders written in AGSL.

The vertex shader defines the varyings, such as position and color, while the fragment shader can optionally define the color for the pixel, typically by using the varyings created by the vertex shader. If color is provided by the fragment shader, it is then blended with the current Paint color using the blend mode selected when drawing the mesh. Uniforms can be passed into the fragment and vertex shaders for additional flexibility.

Trình kết xuất vùng đệm phần cứng cho Canvas

To assist in using Android's Canvas API to draw with hardware acceleration into a HardwareBuffer, Android 14 introduces HardwareBufferRenderer. This API is particularly useful when your use case involves communication with the system compositor through SurfaceControl for low-latency drawing.