Android 16 面向开发者引入了一些出色的新功能和 API。以下部分总结了这些功能,可帮助您开始使用相关 API。
您还应查看平台变更可能会在哪些方面影响您的应用。如需了解详情,请参阅以下页面:
核心功能
Android 包含可扩展 Android 系统核心功能的新 API。
2025 年发布两个 Android API
- 此预览版适用于 Android 的下一个主要版本,计划于 2025 年第 2 季度发布。此版本与我们过去的所有 API 版本类似,我们可以进行计划性的行为更改,这些更改通常与 targetSdkVersion 相关联。
- 我们计划提前一个季度(2021 年第 2 季度,而非之前的第 3 季度)发布主要版本,以便更好地与整个生态系统中的设备发布时间表保持一致,让更多设备能够更早地搭载 Android 主要版本。由于主要版本将于第 2 季度发布,因此您需要比往年提前几个月进行年度兼容性测试,以确保您的应用已做好准备。
- 我们计划在 2025 年第 4 季度再发布一次,届时还将推出新的开发者 API。2025 年只有第二季度的主要版本包含可能影响应用的计划行为变更。
除了新的开发者 API 之外,第 4 季度次要版本还将包含功能更新、优化和 bug 修复;其中不会包含任何会影响应用的行为变更。
我们将继续每季度发布 Android 版本。在 API 版本之间,第 1 季度和第 3 季度的更新将提供增量更新,以帮助确保持续提供高质量的服务。我们正积极与设备合作伙伴合作,将 Q2 版本推广到尽可能多的设备。
在主要版本和次要版本中使用新 API
目前,使用 SDK_INT
常量与 VERSION_CODES
结合使用,即可通过检查 API 级别来保护代码块。我们将继续支持主要 Android 版本。
if (SDK_INT >= VERSION_CODES.BAKLAVA) {
// Use APIs introduced in Android 16
}
新的 SDK_INT_FULL
常量可用于针对主要版本和次要版本进行 API 检查,并使用新的 VERSION_CODES_FULL
枚举。
if (SDK_INT_FULL >= VERSION_CODES_FULL.[MAJOR or MINOR RELEASE]) {
// Use APIs introduced in a major or minor release
}
您还可以使用 Build.getMinorSdkVersion()
方法仅获取 SDK 次要版本。
val minorSdkVersion = Build.getMinorSdkVersion(VERSION_CODES_FULL.BAKLAVA)
这些 API 尚未最终确定,可能会发生变化,因此如果您有任何疑虑,请向我们发送反馈。
用户体验和系统界面
Android 16 让应用开发者和用户可以更好地控制和灵活地配置设备,以满足他们的需求。
预测性返回更新
Android 16 adds new APIs to help you enable predictive back system animations in
gesture navigation such as the back-to-home animation. Registering the
onBackInvokedCallback
with the new
PRIORITY_SYSTEM_NAVIGATION_OBSERVER
allows your app to
receive the regular onBackInvoked
call whenever the
system handles a back navigation without impacting the normal back navigation
flow.
Android 16 additionally adds the
finishAndRemoveTaskCallback()
and
moveTaskToBackCallback
. By registering these callbacks
with the OnBackInvokedDispatcher
, the system can trigger
specific behaviors and play corresponding ahead-of-time animations when the back
gesture is invoked.
更丰富的触感反馈
Android has exposed control over the haptic actuator ever since its inception.
Android 11 added support for more complex haptic effects that more advanced
actuators could support through
VibrationEffect.Compositions
of device-defined semantic
primitives.
Android 16 adds haptic APIs that let apps define the amplitude and frequency curves of a haptic effect while abstracting away differences between device capabilities.
性能和电池
Android 16 引入了一些 API,可帮助您收集有关应用的数据分析。
系统触发的性能分析
ProfilingManager
was
added in Android 15, giving apps the ability to
request profiling data collection using Perfetto on public devices in the field.
However, since this profiling must be started from the app, critical flows such
as startups or ANRs would be difficult or impossible for apps to capture.
To help with this, Android 16 introduces system-triggered profiling to
ProfilingManager
. Apps can register interest in receiving traces for certain
triggers such as cold start reportFullyDrawn
or ANRs, and then the system starts and stops a trace on the app's behalf. After
the trace completes, the results are delivered to the app's data directory.
在 ApplicationStartInfo 中启动组件
ApplicationStartInfo
在 Android 15 中添加,可让应用查看进程启动原因、启动类型、启动时间、节流和其他实用诊断数据。Android 16 添加了 getStartComponent()
,用于区分触发启动的组件类型,这有助于优化应用的启动流程。
更好的作业自省
The JobScheduler#getPendingJobReason()
API returns a reason why a job
might be pending. However, a job might be pending for multiple reasons.
In Android 16, we are introducing a new API
JobScheduler#getPendingJobReasons(int jobId)
, which returns multiple
reasons why a job is pending, due to both explicit constraints set by the
developer and implicit constraints set by the system.
We're also introducing
JobScheduler#getPendingJobReasonsHistory(int jobId)
, which returns a list
of the most recent constraint changes.
We recommend using the API to help you debug why your jobs may not be executing, especially if you're seeing reduced success rates of certain tasks or have bugs around latency of certain job completion. For example, updating widgets in the background failed to occur or prefetch job failed to be called prior to app start.
This can also better help you understand if certain jobs are not completing due to system defined constraints versus explicitly set constraints.
自适应刷新率
Android 15 中引入的自适应刷新率 (ARR) 可让受支持硬件上的显示屏刷新率使用离散的 VSync 步长来适应内容帧速率。这不仅降低了功耗,还无需进行可能导致卡顿的模式切换。
Android 16 引入了 hasArrSupport()
和 getSuggestedFrameRate(int)
,同时恢复了 getSupportedRefreshRates()
,以便您的应用更轻松地利用 ARR。RecyclerView 1.4 在从快速滑动或平滑滚动中稳定下来时会在内部支持 ARR,我们将继续努力,将 ARR 支持添加到更多 Jetpack 库中。这篇帧速率文章介绍了许多可用于设置帧速率的 API,以便您的应用可以直接使用 ARR。
连接
Android 16 更新了平台,让您的应用可以使用通信和无线技术的最新进展。
使用增强型安全功能进行测距
Android 16 在搭载 Wi-Fi 6 的 802.11az 的受支持设备上为 Wi-Fi 位置信息添加了对强大的安全功能的支持,让应用能够将该协议的更高精确性、更高可伸缩性和动态调度与安全增强功能(包括基于 AES-256 的加密和防范中间人攻击)相结合。这样,在近距离使用情形(例如解锁笔记本电脑或车门)时,便可更安全地使用该功能。802.11az 与 Wi-Fi 6 标准集成,可利用其基础架构和功能实现更广泛的采用和更轻松的部署。
媒体
Android 16 包含多种用于改进媒体体验的功能。
改进了照片选择器
The photo picker provides a safe, built-in way for users to grant your app access to selected images and videos from both local and cloud storage, instead of their entire media library. Using a combination of Modular System Components through Google System Updates and Google Play services, it's supported back to Android 4.4 (API level 19). Integration requires just a few lines of code with the associated Android Jetpack library.
Android 16 includes the following improvements to the photo picker:
- Embedded photo picker: New APIs that enable apps to embed the photo picker into their view hierarchy. This allows it to feel like a more integrated part of the app while still leveraging the process isolation that allows users to select media without the app needing overly broad permissions. To maximize compatibility across platform versions and simplify your integration, you'll want to use the forthcoming Android Jetpack library if you want to integrate the embedded photo picker.
- Cloud search in photo picker: New APIs that enable searching from the cloud media provider for the Android photo picker. Search functionality in the photo picker is coming soon.
隐私设置
Android 16 包含多种功能,可帮助应用开发者保护用户隐私。
健康数据共享更新
Health Connect in the developer preview adds ACTIVITY_INTENSITY
, a new
data type defined according to World Health Organization guidelines around
moderate and vigorous activity. Each record requires the start time, the end
time and whether the activity intensity is moderate or vigorous.
Health Connect also contains updated APIs supporting health records. This allows apps to read and write medical records in FHIR format with explicit user consent. This API is in an early access program. If you'd like to participate, sign up to be part of our early access program.
Privacy Sandbox on Android
Android 16 incorporates the latest version of the Privacy Sandbox on Android, part of our ongoing work to develop technologies where users know their privacy is protected. Our website has more about the Privacy Sandbox on Android developer beta program to help you get started. Check out the SDK Runtime which allows SDKs to run in a dedicated runtime environment separate from the app they are serving, providing stronger safeguards around user data collection and sharing.