Nền tảng Android 16 có các thay đổi về hành vi có thể ảnh hưởng đến ứng dụng của bạn. Những thay đổi về hành vi sau đây áp dụng cho tất cả ứng dụng khi chạy trên Android 16, bất kể targetSdkVersion
. Bạn nên kiểm thử ứng dụng rồi sửa đổi để hỗ trợ những thay đổi này cho phù hợp (nếu cần).
Ngoài ra, hãy nhớ tham khảo danh sách thay đổi về hành vi chỉ ảnh hưởng đến những ứng dụng nhắm đến Android 16.
Chức năng cốt lõi
Android 16 (API cấp 36) có những thay đổi sau đây nhằm sửa đổi hoặc mở rộng nhiều chức năng cốt lõi của hệ thống Android.
Tối ưu hoá hạn mức 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
Lý do dừng các công việc bị bỏ dở khi không có dữ liệu
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.
Hoàn toàn không dùng JobInfo#setImportantWhileForeground nữa
Phương thức JobInfo.Builder#setImportantWhileForeground(boolean)
cho biết tầm quan trọng của một công việc trong khi ứng dụng lên lịch chạy ở nền trước hoặc khi tạm thời được miễn các quy định hạn chế về chế độ nền.
Phương thức này không được dùng nữa kể từ Android 12 (API cấp 31). Kể từ Android 16, phương thức này không còn hoạt động hiệu quả và việc gọi phương thức này sẽ bị bỏ qua.
Việc xoá chức năng này cũng áp dụng cho
JobInfo#isImportantWhileForeground()
. Kể từ Android 16, nếu được gọi, phương thức này sẽ trả về false
.
Phạm vi ưu tiên của thông báo truyền tin theo thứ tự không còn là phạm vi toàn cầu nữa
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.
Thay đổi nội bộ về ART
Android 16 includes the latest updates to the Android Runtime (ART) that improve the Android Runtime's (ART's) performance and provide support for additional Java features. Through Google Play System updates, these improvements are also available to over a billion devices running Android 12 (API level 31) and higher.
As these changes are released, libraries and app code that rely on internal structures of ART might not work correctly on devices running Android 16, along with earlier Android versions that update the ART module through Google Play system updates.
Relying on internal structures (such as non-SDK interfaces) can always lead to compatibility problems, but it's particularly important to avoid relying on code (or libraries containing code) that leverages internal ART structures, since ART changes aren't tied to the platform version the device is running on and they go out to over a billion devices through Google Play system updates.
All developers should check whether their app is impacted by testing their apps thoroughly on Android 16. In addition, check the known issues to see if your app depends on any libraries that we've identified that rely on internal ART structures. If you do have app code or library dependencies that are affected, seek public API alternatives whenever possible and request public APIs for new use cases by creating a feature request in our issue tracker.
Chế độ tương thích với kích thước trang 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.

Trải nghiệm người dùng và giao diện người dùng hệ thống
Android 16 (API cấp 36) có những thay đổi sau đây nhằm tạo ra trải nghiệm người dùng nhất quán và trực quan hơn.
Ngừng sử dụng các thông báo hỗ trợ tiếp cận gây phiền toái
Android 16 không dùng thông báo hỗ trợ tiếp cận nữa, được xác định bằng việc sử dụng announceForAccessibility
hoặc gửi sự kiện hỗ trợ tiếp cận TYPE_ANNOUNCEMENT
. Những điều này có thể tạo ra trải nghiệm người dùng không nhất quán cho người dùng TalkBack và trình đọc màn hình của Android, đồng thời các giải pháp thay thế sẽ phục vụ tốt hơn nhiều nhu cầu của người dùng trên nhiều công nghệ hỗ trợ của Android.
Ví dụ về các lựa chọn thay thế:
- Đối với các thay đổi đáng kể về giao diện người dùng như thay đổi cửa sổ, hãy sử dụng
Activity.setTitle(CharSequence)
vàsetAccessibilityPaneTitle(java.lang.CharSequence)
. Trong Compose, hãy sử dụngModifier.semantics { paneTitle = "paneTitle" }
- Để thông báo cho người dùng về những thay đổi đối với giao diện người dùng quan trọng, hãy sử dụng
setAccessibilityLiveRegion(int)
. Trong Compose, hãy sử dụngModifier.semantics { liveRegion = LiveRegionMode.[Polite|Assertive]}
. Bạn nên sử dụng các thông báo này một cách tiết kiệm vì chúng có thể tạo thông báo mỗi khi Chế độ xem được cập nhật. - Để thông báo cho người dùng về lỗi, hãy gửi
AccessibilityEvent
thuộc loạiAccessibilityEvent#CONTENT_CHANGE_TYPE_ERROR
và đặtAccessibilityNodeInfo#setError(CharSequence)
hoặc sử dụngTextView#setError(CharSequence)
.
Tài liệu tham khảo cho API announceForAccessibility
không dùng nữa bao gồm thêm thông tin chi tiết về các giải pháp thay thế được đề xuất.
Hỗ trợ chế độ thao tác bằng 3 nút
Android 16 hỗ trợ tính năng xem trước thao tác quay lại cho chế độ điều hướng bằng 3 nút cho các ứng dụng đã di chuyển đúng cách sang tính năng xem trước thao tác quay lại. Thao tác nhấn và giữ nút quay lại sẽ bắt đầu ảnh động xem trước thao tác quay lại, cho bạn xem trước vị trí mà thao tác vuốt ngược sẽ đưa bạn đến.
Hành vi này áp dụng cho tất cả các khu vực của hệ thống hỗ trợ ảnh động xem trước thao tác quay lại, bao gồm cả ảnh động hệ thống (quay lại màn hình chính, giữa các tác vụ và giữa các hoạt động).
Kiểu dáng thiết bị
Android 16 (API cấp 36) có những thay đổi sau đây đối với các ứng dụng khi được chủ sở hữu thiết bị ảo chiếu lên màn hình.
Chủ sở hữu thiết bị ảo ghi đè
Chủ sở hữu thiết bị ảo là một ứng dụng đáng tin cậy hoặc có đặc quyền tạo và quản lý một thiết bị ảo. Chủ sở hữu thiết bị ảo chạy các ứng dụng trên thiết bị ảo, sau đó chiếu các ứng dụng đó lên màn hình của một thiết bị từ xa, chẳng hạn như máy tính cá nhân, thiết bị thực tế ảo hoặc hệ thống thông tin giải trí trên ô tô. Chủ sở hữu thiết bị ảo đang dùng một thiết bị cục bộ, chẳng hạn như điện thoại di động.

Ghi đè cho mỗi ứng dụng
Trên các thiết bị chạy Android 16 (API cấp 36), chủ sở hữu thiết bị ảo có thể ghi đè chế độ cài đặt ứng dụng trên một số thiết bị ảo mà họ quản lý. Ví dụ: để cải thiện bố cục ứng dụng, chủ sở hữu thiết bị ảo có thể bỏ qua các hạn chế về hướng, tỷ lệ khung hình và khả năng thay đổi kích thước khi chiếu ứng dụng lên màn hình ngoài.
Các thay đổi có thể gây lỗi thường gặp
Hành vi của Android 16 có thể ảnh hưởng đến giao diện người dùng của ứng dụng trên các hệ số hình dạng màn hình lớn, chẳng hạn như màn hình ô tô hoặc Chromebook, đặc biệt là những bố cục được thiết kế cho màn hình nhỏ ở hướng dọc. Để tìm hiểu cách giúp ứng dụng của bạn thích ứng với mọi hệ số hình dạng của thiết bị, hãy xem phần Giới thiệu về bố cục thích ứng.
Tài liệu tham khảo
Truyền phát bằng ứng dụng đồng hành
Bảo mật
Android 16 (API cấp 36) có những thay đổi giúp tăng cường tính bảo mật của hệ thống để bảo vệ ứng dụng và người dùng khỏi các ứng dụng độc hại.
Cải thiện khả năng bảo mật để chống lại các cuộc tấn công chuyển hướng Ý định
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) }
Ứng dụng đồng hành sẽ không còn nhận được thông báo về thời gian chờ phát hiện nữa
Android 16 在配套设备配对流程期间引入了一种新行为,以防恶意应用侵犯用户的位置信息隐私。在 Android 16 上运行的所有配套应用都不再直接通过 RESULT_DISCOVERY_TIMEOUT
收到发现超时通知。而是通过可视对话框通知用户超时事件。当用户关闭对话框时,系统会通过 RESULT_USER_REJECTED
提醒应用关联失败。
搜索时长也从原来的 20 秒延长到了 30 秒,并且用户可以在搜索期间的任何时间停止设备发现。如果在开始搜索的前 20 秒内发现了至少 1 部设备,CDM 会停止搜索其他设备。
Khả năng kết nối
Android 16 (API cấp 36) có những thay đổi sau đây trong ngăn xếp Bluetooth để cải thiện khả năng kết nối với các thiết bị ngoại vi.
Cải thiện khả năng xử lý tình trạng mất liên kết
Kể từ Android 16, ngăn xếp Bluetooth đã được cập nhật để cải thiện tính bảo mật và trải nghiệm người dùng khi phát hiện thấy mất liên kết từ xa. Trước đây, hệ thống sẽ tự động xoá mối liên kết và bắt đầu một quy trình ghép nối mới, điều này có thể dẫn đến việc ghép nối lại ngoài ý muốn. Chúng tôi nhận thấy trong nhiều trường hợp, các ứng dụng không xử lý sự kiện mất liên kết một cách nhất quán.
Để hợp nhất trải nghiệm, Android 16 đã cải thiện khả năng xử lý mất liên kết với hệ thống. Nếu không xác thực được thiết bị Bluetooth đã liên kết trước đó khi kết nối lại, hệ thống sẽ ngắt kết nối đường liên kết, giữ lại thông tin liên kết cục bộ và hiển thị hộp thoại hệ thống thông báo cho người dùng về việc mất liên kết và hướng dẫn họ ghép nối lại.