行为变更:所有应用

Android 14 平台包含一些行为变更,这些变更可能会影响您的应用。以下行为变更将影响在 Android 14 上运行的所有应用,无论采用哪种 targetSdkVersion 都不例外。您应该测试您的应用,然后根据需要进行修改,以适当地支持这些变更。

此外,请务必查看仅影响以 Android 14 为目标平台的应用的行为变更列表。

核心功能

默认拒绝设定精确的闹钟

Exact alarms are meant for user-intentioned notifications, or for actions that need to happen at a precise time. Starting in Android 14, the SCHEDULE_EXACT_ALARM permission is no longer being pre-granted to most newly installed apps targeting Android 13 and higher—the permission is denied by default.

Learn more about the changes to the permission for scheduling exact alarms.

当应用进入缓存时,上下文注册的广播将加入队列

On Android 14, the system can place context-registered broadcasts in a queue while the app is in the cached state. This is similar to the queuing behavior that Android 12 (API level 31) introduced for async binder transactions. Manifest-declared broadcasts aren't queued, and apps are removed from the cached state for broadcast delivery.

When the app leaves the cached state, such as returning to the foreground, the system delivers any queued broadcasts. Multiple instances of certain broadcasts might be merged into one broadcast. Depending on other factors, such as system health, apps might be removed from the cached state, and any previously queued broadcasts are delivered.

应用只能终止自己的后台进程

从 Android 14 开始,当您的应用调用 killBackgroundProcesses() 时,该 API 只能终止您自己应用的后台进程。

如果您传入另一个应用的软件包名称,此方法对该应用的后台进程没有影响,并且 Logcat 中会显示以下消息:

Invalid packageName: com.example.anotherapp

您的应用不应使用 killBackgroundProcesses() API,也不得以其他方式尝试影响其他应用的进程生命周期,即使在旧版操作系统上也是如此。Android 旨在让缓存应用在后台运行,并在系统需要内存时自动终止它们。如果您的应用会不必要地终止其他应用,则由于之后需要完全重启这些应用,因此可能会降低系统性能并增加耗电量,这比恢复现有缓存应用所消耗的资源要多得多。

第一个请求 MTU 的 GATT 客户端的 MTU 设置为 517

Starting from Android 14, the Android Bluetooth stack more strictly adheres to Version 5.2 of the Bluetooth Core Specification and requests the BLE ATT MTU to 517 bytes when the first GATT client requests an MTU using the BluetoothGatt#requestMtu(int) API, and disregards all subsequent MTU requests on that ACL connection.

To address this change and make your app more robust, consider the following options:

  • Your peripheral device should respond to the Android device's MTU request with a reasonable value that can be accommodated by the peripheral. The final negotiated value will be a minimum of the Android requested value and the remote provided value (for example, min(517, remoteMtu))
    • Implementing this fix could require a firmware update for peripheral
  • Alternatively, limit your GATT characteristic writes based on the minimum between the known supported value of your peripheral and the received MTU change
    • A reminder that you should reduce 5 bytes from the supported size for the headers
    • For example: arrayMaxLength = min(SUPPORTED_MTU, GATT_MAX_ATTR_LEN(517)) - 5

可将应用放入“受限待机”分桶的新原因

Android 14 introduces a new reason an app can be placed into the restricted standby bucket. The app's jobs trigger ANR errors multiple times due to onStartJob, onStopJob, or onBind method timeouts. (See JobScheduler reinforces callback and network behavior for changes to onStartJob and onStopJob.)

To track whether or not the app has entered the restricted standby bucket, we recommend logging with the API UsageStatsManager.getAppStandbyBucket() on job execution or UsageStatsManager.queryEventsForSelf() on app startup.

mlock 限制为 64 KB

In Android 14 (API level 34) and higher, the platform reduces the maximum memory that can be locked using mlock() to 64 KB per process. In previous versions, the limit was 64 MB per process. This restriction promotes better memory management across apps and the system. To provide more consistency across devices, Android 14 adds a new CTS test for the new mlock() limit on compatible devices.

系统强制使用缓存的应用资源

从设计上讲,当应用的进程移至后台且没有任何其他应用进程组件在运行时,应用进程将处于缓存状态。此类应用进程可能会因系统内存压力而终止。在此状态下,Activity 实例在调用并返回 onStop() 方法后执行的任何工作均不可靠,强烈建议不要这样做。

Android 14 对此设计引入了一致性和强制执行要求。在应用进程进入缓存状态后不久,系统会禁止后台工作,直到进程组件重新进入生命周期的活跃状态。

使用框架支持的典型生命周期 API(例如服务JobSchedulerJetpack WorkManager)的应用应该不受这些变化的影响。

用户体验

关于不可关闭通知用户体验方式的变更

如果您的应用向用户显示不可关闭的前台通知,请注意:Android 14 已更改此行为,允许用户关闭此类通知。

这项变更适用于通过 Notification.Builder#setOngoing(true)NotificationCompat.Builder#setOngoing(true) 设置 Notification.FLAG_ONGOING_EVENT 来阻止用户关闭前台通知的应用。FLAG_ONGOING_EVENT 的行为已发生变化,使用户实际上能够关闭此类通知。

在以下情况下,此类通知仍不可关闭:

  • 当手机处于锁定状态时
  • 如果用户选择全部清除通知操作(有助于防止意外关闭)

此外,这种新行为不适用于以下用例中的通知:

  • CallStyle 通知
  • 企业设备政策控制器 (DPC) 和支持软件包
  • 媒体通知
  • 默认的搜索选择器软件包

数据安全信息更显眼

为了加强用户隐私保护,Android 14 增加了系统显示您在 Play 管理中心表单中声明的信息的位置数量。目前,用户可以在 Google Play 中的应用详情的数据安全部分查看此信息。

我们建议您查看应用的位置数据分享政策,并花一点时间对应用的 Google Play“数据安全”部分进行任何适用的更新。

如需了解详情,请参阅有关如何在 Android 14 上以更显眼的方式显示数据安全信息的指南。

无障碍功能

非线性字体放大至 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).

If you already use scaled pixels (sp) units to define text sizing, then this change probably won't have a high impact on your app. However, you should perform UI testing with the maximum font size enabled (200%) to ensure that your app can accommodate larger font sizes without impacting usability.

安全

最低可安装的目标 API 级别

Starting with Android 14, apps with a targetSdkVersion lower than 23 can't be installed. Requiring apps to meet these minimum target API level requirements improves security and privacy for users.

Malware often targets older API levels in order to bypass security and privacy protections that have been introduced in newer Android versions. For example, some malware apps use a targetSdkVersion of 22 to avoid being subjected to the runtime permission model introduced in 2015 by Android 6.0 Marshmallow (API level 23). This Android 14 change makes it harder for malware to avoid security and privacy improvements. Attempting to install an app targeting a lower API level will result in an installation failure, with the following message appearing in Logcat:

INSTALL_FAILED_DEPRECATED_SDK_VERSION: App package must target at least SDK version 23, but found 7

On devices upgrading to Android 14, any apps with a targetSdkVersion lower than 23 will remain installed.

If you need to test an app targeting an older API level, use the following ADB command:

adb install --bypass-low-target-sdk-block FILENAME.apk

媒体所有者软件包名称可能会隐去

The media store supports queries for the OWNER_PACKAGE_NAME column, which indicates the app that stored a particular media file. Starting in Android 14, this value is redacted unless at least one of the following conditions is true:

  • The app that stored the media file has a package name that is always visible to other apps.
  • The app that queries the media store requests the QUERY_ALL_PACKAGES permission.

Learn more about how Android filters package visibility for privacy purposes.