行为变更:所有应用

Android 15 平台包含一些行为变更,这些变更可能会影响您的应用。 以下行为变更将影响在 Android 15 上运行的所有应用, 而不考虑 targetSdkVersion。您应该测试您的应用,然后修改 以适当地支持这些内容(如果适用)。

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

核心功能

Android 15 修改或扩展了 Android 系统的各种核心功能。

对软件包停止状态的更改

The intention of the package FLAG_STOPPED state (which users can engage in AOSP builds by long-pressing an app icon and selecting "Force Stop") has always been to keep apps in this state until the user explicitly removes the app from this state by directly launching the app or indirectly interacting with the app (through the sharesheet or a widget, selecting the app as live wallpaper, etc.). In Android 15, we are updating the behavior of the system to be aligned with this intended behavior. Apps should only be removed from the stopped state through direct or indirect user action.

To support the intended behavior, in addition to the existing restrictions, the system also cancels all pending intents when the app enters the stopped state on a device running Android 15. When the user's actions remove the app from the stopped state, the ACTION_BOOT_COMPLETED broadcast is delivered to the app providing an opportunity to re-register any pending intents.

You can call the new ApplicationStartInfo.wasForceStopped() method to confirm whether the app was put into the stopped state.

支持 16 KB 页面大小

Android 过去仅支持 4 KB 内存页面大小, 优化了系统内存性能,以针对 Android 设备通常具备的功能。从 Android 15 开始,AOSP 支持 配置为使用 16 KB (16 KB) 页面大小的设备 设备)。如果您的应用使用任何 NDK 库,请直接使用 或者通过 SDK 间接创建,那么,您需要重新构建自己的应用 支持这些 16KB 设备。

随着设备制造商不断打造出 物理内存 (RAM),许多此类设备都会采用 16KB(以及 页面大小以优化设备的性能。正在添加 支持 16 KB 页面大小的设备,可使您的应用在这些设备上运行 并有助于您的应用从相关的广告效果中获益 改进。如果不重新编译,应用可能无法在 16KB 设备上运行 在未来的 Android 版本中正式推出。

为帮助您为应用添加支持,我们提供了有关如何检查 如果您的应用受到影响 重新构建您的应用(如果适用),以及如何在 Google Play 中 使用模拟器(包括 Android 15)的 16 KB 环境 系统映像)。

优势和性能提升

配置为 16 KB 页面的设备平均使用的内存会略多,但系统和应用性能也会有所提升:

  • 在系统面临内存压力时缩短应用启动时间:平均降低了 3.16%,对于我们测试过的一些应用而言,改进幅度更显著(提升幅度高达 30%)
  • 降低应用启动时的功耗:平均降低 4.56%
  • 相机启动速度更快:平均热启动速度加快 4.48%,冷启动速度平均加快 6.60%
  • 缩短了系统启动时间:平均缩短了 1.5%(约 0.8 秒)

这些改进基于我们的初始测试,实际设备上的结果可能会有所不同。在继续测试的过程中,我们会进一步分析应用的潜在益处。

检查您的应用是否受到影响

如果您的应用使用任何原生代码,则您应重新构建支持 16 KB 设备的应用。如果您不确定自己的应用是否使用了原生代码,可以使用 APK 分析器来确定是否存在任何原生代码

如果您的应用仅使用以 Java 编程语言或 Kotlin 编写的代码(包括所有库或 SDK),那么该应用已经支持 16 KB 设备。不过,我们建议您在 16 KB 的环境中测试应用,以确认应用行为是否存在意外回归问题。

让部分应用支持私密空间所需的更改

私密空间是 Android 15 中的一项新功能,可让用户 在设备上创建一个单独的空间,以便将敏感应用拒之门外 增加了一层额外的身份验证。因为 由于私密空间的公开范围有限,因此某些类型的应用需要 需要完成一些额外步骤才能查看用户私有中的应用并与之互动 空间。

所有应用

由于私密空间中的应用保存在单独的用户个人资料中, 工作资料,则应用不应假定已安装任何 不在主资料中的应用副本位于工作资料中。如果 您的应用具有与工作资料应用相关的逻辑,这类应用会做出这种假设, 您需要调整此逻辑。

医疗应用

当用户锁定私密空间后,私密空间中的所有应用都会停止, 并且这些应用无法执行前台或后台 activity,包括 显示通知。这种行为可能会严重影响 安装在私密空间中的医疗应用的功能。

设置私密空间时,系统会警告用户私密空间 适用于需要执行关键前台或后台任务的应用 活动,例如显示来自医疗应用的通知。不过, 应用无法确定其是否被用在私密空间中; 这样他们就无法针对这种情况向用户显示警告。

出于这些原因,如果您开发了医疗应用,请查看此功能可能会给 影响您的应用并采取适当措施,例如告知用户不要 在私密空间中安装您的应用,以免干扰关键应用 功能。

启动器应用

如果您要开发启动器应用,必须先执行以下操作,然后再运行 以下私密空间:

  1. 您必须将应用指定为设备的默认启动器应用, 具有 ROLE_HOME 角色。
  2. 您的应用必须声明 ACCESS_HIDDEN_PROFILES 普通权限。

声明 ACCESS_HIDDEN_PROFILES 权限的启动器应用必须处理 私密空间的使用场景如下:

  1. 您的应用必须为安装在 私密空间使用 getLauncherUserInfo() 方法 确定正在处理的用户个人资料类型。
  2. 用户必须能够隐藏和显示私密空间容器。
  3. 用户必须能够锁定和解锁私密空间容器。使用 requestQuietModeEnabled() 方法锁定(通过 传递 true)或解锁(通过传递 false)私密空间。
  4. 处于锁定状态时,私密空间容器中的任何应用都不应可见或 可通过搜索等机制发现。您的应用应注册 接收器 ACTION_PROFILE_AVAILABLEACTION_PROFILE_UNAVAILABLE 广播,并更新 私密空间处于锁定或解锁状态时应用中的界面 容器更改这两种广播都包含 EXTRA_USER,您的应用可以使用它来引用 个人资料用户。

    您还可以使用 isQuietModeEnabled() 方法 检查私密空间配置文件是否处于锁定状态。

应用商店应用

私密空间包括“安装应用”启动隐式 intent 来将应用安装到用户的私密空间中。为了让您的应用 收到此隐式 intent,请声明 <intent-filter> 在应用的清单文件中,使用 <category> CATEGORY_APP_MARKET

移除了基于 PNG 的表情符号字体

The legacy, PNG-based emoji font file (NotoColorEmojiLegacy.ttf) has been removed, leaving just the vector-based file. Beginning with Android 13 (API level 33), the emoji font file used by the system emoji renderer changed from a PNG-based file to a vector based file. The system retained the legacy font file in Android 13 and 14 for compatibility reasons, so that apps with their own font renderers could continue to use the legacy font file until they were able to upgrade.

To check if your app is affected, search your app's code for references to the NotoColorEmojiLegacy.ttf file.

You can choose to adapt your app in a number of ways:

  • Use platform APIs for text rendering. You can render text to a bitmap-backed Canvas and use that to get a raw image if necessary.
  • Add COLRv1 font support to your app. The FreeType open source library supports COLRv1 in version 2.13.0 and higher.
  • As a last resort, you can bundle the legacy emoji font file (NotoColorEmoji.ttf) into your APK, although in that case your app will be missing the latest emoji updates. For more information, see the Noto Emoji GitHub project page.

将最低目标 SDK 版本从 23 提高到了 24

Android 15 builds on the the changes that were made in Android 14 and extends this security further. In Android 15, apps with a targetSdkVersion lower than 24 can't be installed. Requiring apps to meet modern API levels helps to ensure better security and privacy.

Malware often targets lower API levels in order to bypass security and privacy protections that have been introduced in higher 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 15 change makes it harder for malware to avoid security and privacy improvements. Attempting to install an app targeting a lower API level results in an installation failure, with a message like the following one appearing in Logcat:

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

On devices upgrading to Android 15, any apps with a targetSdkVersion lower than 24 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

摄像头和媒体

Android 15 针对所有用户的相机和媒体行为做出了以下变更 。

现在,当达到资源限制时,直接和分流音频播放会使之前打开的直接或分流音轨失效

在 Android 15 之前,如果某个应用在另一个应用正在播放音频时请求直接播放或分流音频播放,并且已达到资源限制,此应用将无法打开新的 AudioTrack

从 Android 15 开始,当应用请求直接或分流播放并且达到资源限制时,系统会使当前打开的所有 AudioTrack 对象失效,从而阻止执行新的轨道请求。

(直接和分流音轨通常会打开,以播放压缩的音频格式。播放直接音频的常见用例包括通过 HDMI 将编码音频流式传输到电视。分流轨道通常用于在具有硬件 DSP 加速的移动设备上播放压缩音频。)

用户体验和系统界面

Android 15 包含一些旨在打造更一致、更完善的 直观的用户体验。

已为已选择启用预测性返回动画功能启用

从 Android 15 开始,移除了预测性返回动画的开发者选项。现在,对于已完全或在 activity 级别选择启用预测性返回手势的应用,系统现在会显示“返回主屏幕”“跨任务”和“跨 activity”等系统动画。如果您的应用受到影响,请执行以下操作:

  • 确保您的应用已正确迁移,以使用预测性返回手势。
  • 确保您的 fragment 转换支持预测性返回导航。
  • 停止使用动画和框架转换,并改用 Animator 和 AndroidX 转换。
  • FragmentManager 不知道的返回堆栈中迁出。请改用由 FragmentManager 或 Navigation 组件管理的返回堆栈。

用户强行停止应用时停用的微件

如果用户在搭载 Android 15 的设备上强行停止某个应用,系统会暂时停用该应用的所有 widget。这些 widget 会灰显,用户无法与它们互动。这是因为,从 Android 15 开始,当应用被强行停止时,系统会取消应用的所有待处理 intent。

系统会在用户下次启动应用时重新启用这些 widget。

如需了解详情,请参阅对软件包停止状态的更改

废弃

随着每个版本的发布,特定的 Android API 可能会过时或需要 进行了重构,以提供更好的开发者体验或支持新平台 capabilities.在这些情况下,我们正式弃用已过时的 API,并 引导开发者改用替代 API。

弃用意味着我们已结束对这些 API 的正式支持,但它们 也可供开发者使用要详细了解值得关注的重要内容 请参阅弃用页面