Android 16 平台包含可能對應用程式造成影響的行為變更。無論 targetSdkVersion
為何,當應用程式在 Android 16 上執行時,下列行為變更將會套用至所有應用程式。您應測試應用程式,並視需要修改,以便在適當情況下支援這些變更。
另請務必查看僅對指定 Android 16 為目標版本的應用程式造成影響的行為變更。
核心功能
Android 16 (API 級別 36) 包含下列變更,可修改或擴充 Android 系統的各種核心功能。
JobScheduler 配額最佳化
自 Android 16 起,我們會根據下列因素調整一般和快速工作執行的執行時間配額:
- 應用程式位於哪個應用程式待命值區:在 Android 16 中,系統會開始以充裕的執行階段配額強制執行有效待命值區。
- 如果工作在應用程式處於頂層狀態時開始執行:在 Android 16 中,如果工作在應用程式向使用者顯示時開始執行,並在應用程式不再顯示後繼續執行,則會遵守工作執行時間配額。
- 如果工作在執行前景服務時執行:在 Android 16 中,與前景服務同時執行的工作會遵守工作執行時間配額。如果您要使用工作來進行使用者啟動的資料移轉作業,請考慮改用使用者啟動的資料移轉工作。
這項異動會影響使用 WorkManager、JobScheduler 和 DownloadManager 排定的任務。如要對工作停止的原因進行偵錯,建議您呼叫 WorkInfo.getStopReason()
來記錄工作停止的原因 (JobScheduler 工作請呼叫 JobParameters.getStopReason()
)。
如要進一步瞭解應用程式狀態如何影響可使用的資源,請參閱「電源管理資源限制」。如要進一步瞭解電池最佳化最佳做法,請參閱最佳化工作排程 API 的電池用量相關指南。
我們也建議您利用 Android 16 中推出的新 JobScheduler#getPendingJobReasonsHistory
API,瞭解為何未執行工作。
測試
如要測試應用程式的行為,只要應用程式在 Android 16 裝置上執行,您就可以啟用特定工作配額最佳化設定的覆寫功能。
如要停用「頂層狀態會遵守工作執行時間配額」的強制執行,請執行下列 adb
指令:
adb shell am compat enable OVERRIDE_QUOTA_ENFORCEMENT_TO_TOP_STARTED_JOBS APP_PACKAGE_NAME
如要停用「與前景服務同時執行的作業會遵守作業執行時間配額」的強制執行功能,請執行下列 adb
指令:
adb shell am compat enable OVERRIDE_QUOTA_ENFORCEMENT_TO_FGS_JOBS APP_PACKAGE_NAME
如要測試特定的應用程式待命值區行為,您可以使用下列 adb
指令設定應用程式的應用程式待命值區:
adb shell am set-standby-bucket APP_PACKAGE_NAME active|working_set|frequent|rare|restricted
如要瞭解應用程式所屬的應用程式待命值區,您可以使用下列 adb
指令取得應用程式的應用程式待命值區:
adb shell am get-standby-bucket APP_PACKAGE_NAME
因工作空白而停止的原因
An abandoned job occurs when the JobParameters
object associated with the job
has been garbage collected, but JobService#jobFinished(JobParameters,
boolean)
has not been called to signal job completion. This indicates that
the job may be running and being rescheduled without the app's awareness.
Apps that rely on JobScheduler, don't maintain a strong reference to the
JobParameters
object, and timeout will now be granted the new job stop reason
STOP_REASON_TIMEOUT_ABANDONED
, instead of STOP_REASON_TIMEOUT
.
If there are frequent occurrences of the new abandoned stop reason, the system will take mitigation steps to reduce job frequency.
Apps should use the new stop reason to detect and reduce abandoned jobs.
If you're using WorkManager, AsyncTask, or DownloadManager, you aren't impacted because these APIs manage the job lifecycle on your app's behalf.
完全淘汰 JobInfo#setImportantWhileForeground
The JobInfo.Builder#setImportantWhileForeground(boolean)
method indicates the importance of a job while the scheduling app is in the
foreground or when temporarily exempted from background restrictions.
This method has been deprecated since Android 12 (API level 31). Starting in Android 16, it no longer functions effectively and calling this method will be ignored.
This removal of functionality also applies to
JobInfo#isImportantWhileForeground()
. Starting in Android
16, if the method is called, the method returns false
.
已排序的廣播優先順序範圍不再是全域
Android apps are allowed to define priorities on broadcast receivers to control
the order in which the receivers receive and process the broadcast. For
manifest-declared receivers, apps can use the
android:priority
attribute to define the priority and for
context-registered receivers, apps can use the
IntentFilter#setPriority()
API to define the priority. When
a broadcast is sent, the system delivers it to receivers in order of their
priority, from highest to lowest.
In Android 16, broadcast delivery order using the android:priority
attribute
or IntentFilter#setPriority()
across different processes will not be
guaranteed. Broadcast priorities will only be respected within the same
application process rather than across all processes.
Also, broadcast priorities will be automatically confined to the range
(SYSTEM_LOW_PRIORITY
+ 1,
SYSTEM_HIGH_PRIORITY
- 1). Only system components will be
allowed to set SYSTEM_LOW_PRIORITY
, SYSTEM_HIGH_PRIORITY
as broadcast
priority.
Your app might be impacted if it does either of the following:
- Your application has declared multiple processes with the same broadcast intent, and has expectations around receiving those intents in a certain order based on the priority.
- Your application process interacts with other processes and has expectations around receiving a broadcast intent in a certain order.
If the processes need to coordinate with each other, they should communicate using other coordination channels.
ART 內部變更
Android 16 包含 Android 运行时 (ART) 的最新更新,这些更新可提升 Android 运行时 (ART) 的性能,并支持更多 Java 功能。通过 Google Play 系统更新,搭载 Android 12(API 级别 31)及更高版本的 10 亿多部设备也将受益于这些改进。
发布这些变更后,依赖于 ART 内部结构的库和应用代码在搭载 Android 16 的设备以及通过 Google Play 系统更新来更新 ART 模块的较低 Android 版本上可能无法正常运行。
依赖于内部结构(例如非 SDK 接口)始终会导致兼容性问题,但避免依赖于利用内部 ART 结构的代码(或包含代码的库)尤为重要,因为 ART 更改与设备所运行的平台版本无关,并且会通过 Google Play 系统更新推送到超过 10 亿部设备。
所有开发者都应在 Android 16 上对其应用进行全面测试,以检查其应用是否受到影响。此外,请查看已知问题,了解您的应用是否依赖于我们发现的任何依赖于内部 ART 结构的库。如果您的应用代码或库依赖项受到影响,请尽可能寻找公共 API 替代方案,并在问题跟踪器中创建功能请求,为新用例请求公共 API。
16 KB 頁面大小相容模式
Android 15 introduced support for 16 KB memory pages to optimize performance of the platform. Android 16 adds a compatibility mode, allowing some apps built for 4 KB memory pages to run on a device configured for 16 KB memory pages.
When your app is running on a device with Android 16 or higher, if Android
detects that your app has 4 KB aligned memory pages, it automatically uses
compatibility mode and display a notification dialog to the user. Setting the
android:pageSizeCompat
property in the AndroidManifest.xml
to enable the
backwards compatibility mode will prevent the display of the dialog when your
app launches. To use the android:pageSizeCompat
property, compile your app
using the Android 16 SDK.
For best performance, reliability, and stability, your app should still be 16 KB aligned. Check out our recent blog post on updating your apps to support 16 KB memory pages for more details.

使用者體驗和系統 UI
Android 16 (API 級別 36) 包含下列異動,旨在打造更一致、直觀的使用者體驗。
淘汰令人混淆的無障礙工具公告
Android 16 废弃了无障碍功能通告,其特征是使用 announceForAccessibility
或调度 TYPE_ANNOUNCEMENT
无障碍功能事件。这可能会给 TalkBack 和 Android 屏幕阅读器用户带来不一致的用户体验,而替代方案可以更好地满足各种 Android 辅助技术的用户需求。
替代方案示例:
- 对于窗口更改等重大界面更改,请使用
Activity.setTitle(CharSequence)
和setAccessibilityPaneTitle(java.lang.CharSequence)
。在 Compose 中,使用Modifier.semantics { paneTitle = "paneTitle" }
- 如需向用户告知关键界面的更改,请使用
setAccessibilityLiveRegion(int)
。在 Compose 中,请使用Modifier.semantics { liveRegion = LiveRegionMode.[Polite|Assertive]}
。应谨慎使用这些事件,因为它们可能会在每次更新视图时生成通知。 - 如需向用户发送错误通知,请发送类型为
AccessibilityEvent#CONTENT_CHANGE_TYPE_ERROR
的AccessibilityEvent
并设置AccessibilityNodeInfo#setError(CharSequence)
,或使用TextView#setError(CharSequence)
。
已废弃的 announceForAccessibility
API 的参考文档中包含有关建议替代方案的更多详细信息。
支援三按鈕操作模式
Android 16 为已正确迁移到预测性返回的应用的三按钮导航栏引入了预测性返回支持。长按返回按钮会启动预测性返回动画,让您预览返回滑动手势会打开的界面。
此行为适用于系统中支持预测性返回动画的所有区域,包括系统动画(返回主屏幕、跨任务和跨 activity)。
裝置板型規格
Android 16 (API 級別 36) 包含以下變更,適用於虛擬裝置擁有者將應用程式投放到螢幕時。
虛擬裝置擁有者覆寫
虚拟设备所有者是创建和管理虚拟设备的受信任应用或特权应用。虚拟设备所有者在虚拟设备上运行应用,然后将应用投影到远程设备的显示屏上,例如个人电脑、虚拟现实设备或车载信息娱乐系统。虚拟设备所有者位于本地设备上,例如手机。

按应用替换项
在搭载 Android 16(API 级别 36)的设备上,虚拟设备所有者可以替换其管理的特定虚拟设备上的应用设置。例如,为了改进应用布局,虚拟设备所有者在将应用投影到外部显示屏上时,可以忽略屏幕方向、宽高比和可调整大小性限制。
常见的重大更改
Android 16 行为可能会影响应用在汽车显示屏或 Chromebook 等大屏幕设备上的界面,尤其是那些专为竖屏小显示屏设计的布局。如需了解如何让应用适应所有设备类型,请参阅关于自适应布局。
参考编号
安全性
Android 16 (API 級別 36) 包含多項異動,可提升系統安全性,協助保護應用程式和使用者免受惡意應用程式侵害。
安全性提高,避免意圖重新導向攻擊
Android 16 提供了针对一般 Intent
重定向攻击的默认安全性,并且只需进行最低限度的兼容性更改和开发者更改。
我们正在推出默认安全强化解决方案,以应对重定向漏洞。Intent
在大多数情况下,使用 intent 的应用通常不会遇到任何兼容性问题;我们在整个开发过程中收集了指标,以监控哪些应用可能会出现中断。
当攻击者可以部分或完全控制用于在存在漏洞的应用上下文中启动新组件的 intent 内容时,Android 中就会出现 intent 重定向问题,而受害应用会在(“顶级”)Intent 的 extras 字段中启动不可信的子级 intent。这可能会导致攻击者应用在受害者应用的上下文中启动私有组件、触发特权操作或获得对敏感数据的 URI 访问权限,从而可能导致数据盗窃和任意代码执行。
选择停用 intent 重定向处理
Android 16 引入了一项新 API,允许应用选择停用启动安全保护功能。在默认安全行为会干扰正当应用用例的特定情况下,这可能是必要的。
对于针对 Android 16(API 级别 36)SDK 或更高版本进行编译的应用
您可以直接对 Intent 对象使用 removeLaunchSecurityProtection()
方法。
val i = intent
val iSublevel: Intent? = i.getParcelableExtra("sub_intent")
iSublevel?.removeLaunchSecurityProtection() // Opt out from hardening
iSublevel?.let { startActivity(it) }
对于针对 Android 15(API 级别 35)或更低版本进行编译的应用
虽然不建议这样做,但您可以使用反射来访问 removeLaunchSecurityProtection()
方法。
val i = intent
val iSublevel: Intent? = i.getParcelableExtra("sub_intent", Intent::class.java)
try {
val removeLaunchSecurityProtection = Intent::class.java.getDeclaredMethod("removeLaunchSecurityProtection")
removeLaunchSecurityProtection.invoke(iSublevel)
} catch (e: Exception) {
// Handle the exception, e.g., log it
} // Opt-out from the security hardening using reflection
iSublevel?.let { startActivity(it) }
隨附應用程式不再收到探索逾時通知
Android 16 在配套设备配对流程期间引入了一种新行为,以防恶意应用侵犯用户的位置信息隐私。在 Android 16 上运行的所有配套应用都不再直接通过 RESULT_DISCOVERY_TIMEOUT
收到发现超时通知。而是通过可视对话框通知用户超时事件。当用户关闭对话框时,系统会通过 RESULT_USER_REJECTED
提醒应用关联失败。
搜索时长也从原来的 20 秒延长到了 30 秒,并且用户可以在搜索期间的任何时间停止设备发现。如果在开始搜索的前 20 秒内发现了至少 1 部设备,CDM 会停止搜索其他设备。
連線能力
Android 16 (API 級別 36) 的藍牙堆疊包含下列變更,可提升與周邊裝置的連線能力。
改善債券損失處理方式
Starting in Android 16, the Bluetooth stack has been updated to improve security and user experience when a remote bond loss is detected. Previously, the system would automatically remove the bond and initiate a new pairing process, which could lead to unintentional re-pairing. We have seen in many instances apps not taking care of the bond loss event in a consistent way.
To unify the experience, Android 16 improved the bond loss handling to the system. If a previously bonded Bluetooth device could not be authenticated upon reconnection, the system will disconnect the link, retain local bond information, and display a system dialog informing users of the bond loss and directing them to re-pair.