功能與 API 總覽

Android 15 為開發人員推出了強大的新功能和 API。下列各節總結這些功能,協助您開始使用相關的 API。

如需新增、修改及移除 API 的詳細清單,請參閱 API 差異比較表。如要進一步瞭解新 API,請造訪 Android API 參考資料。系統會醒目顯示新的 API,方便您查看。此外,如要瞭解平台異動可能會影響應用程式的哪些部分,請務必查看 Android 15 鎖定 Android 15 時影響應用程式的行為變更,以及影響所有應用程式 (無論 targetSdkVersion 為何) 的行為變更

相機與媒體

Android 15 包含多項功能,可改善相機和媒體體驗,並提供相關工具和硬體,協助創作者在 Android 平台上實現願景。

應用程式內相機控制選項

Android 15 新增了擴充功能,讓你在支援的裝置上進一步控管相機硬體及其演算法:

  • 進階閃光燈強度調整功能,可讓您在拍照時精確控制 SINGLETORCH 模式的閃光燈強度。

HDR 進步空間控制

Android 15 會選擇適用於面板的基礎裝置功能和位元深度的 HDR 進步空間。如果頁面含有大量 SDR 內容 (例如顯示單一 HDR 縮圖的訊息應用程式),這項行為最後可能影響 SDR 內容的亮度。Android 15 可讓您使用 setDesiredHdrHeadroom 控制 HDR 進步空間,在 SDR 和 HDR 內容之間取得平衡。

與右側畫面的亮度相比,左側 SDR UI 元素的亮度似乎更加統一,可以模擬 HDR 和 SDR 內容混合時可能發生的上升空間問題。只要調整 HDR 進步空間,就能在 SDR 和 HDR 內容之間取得更平衡。

音量控制

Android 15 introduces support for the CTA-2075 loudness standard to help you avoid audio loudness inconsistencies and ensure users don't have to constantly adjust volume when switching between content. The system leverages known characteristics of the output devices (headphones and speaker) along with loudness metadata available in AAC audio content to intelligently adjust the audio loudness and dynamic range compression levels.

To enable this feature, you need to ensure loudness metadata is available in your AAC content and enable the platform feature in your app. For this, you instantiate a LoudnessCodecController object by calling its create factory method with the audio session ID from the associated AudioTrack; this automatically starts applying audio updates. You can pass an OnLoudnessCodecUpdateListener to modify or filter loudness parameters before they are applied on the MediaCodec.

// Media contains metadata of type MPEG_4 OR MPEG_D
val mediaCodec = …
val audioTrack = AudioTrack.Builder()
                                .setSessionId(sessionId)
                                .build()
...
// Create new loudness controller that applies the parameters to the MediaCodec
try {
   val lcController = LoudnessCodecController.create(mSessionId)
   // Starts applying audio updates for each added MediaCodec

AndroidX media3 ExoPlayer will soon be updated to leverage LoudnessCodecController APIs for a seamless app integration.

低光源增強

Android 15 引入了低光增强,这是一种新的自动曝光模式,可供 Camera 2夜间模式相机扩展使用。“低光增强”功能可调整预览视频流在弱光条件下的曝光量。这与夜间模式相机扩展程序创建静态图片的方式不同,因为夜间模式会组合多张照片来制作单张增强图片。虽然夜间模式非常适合创建静态图片,但无法创建连续的帧流,但“低光增强”可以。因此,“低光增强”可以实现新的相机功能,例如:

  • 提供增强的图片预览,以便用户更好地为弱光环境取景
  • 在光线昏暗的环境下扫描二维码

如果您启用“弱光增强”,它会在光线较暗时自动开启,在光线较暗时关闭。

应用可以在光线昏暗的环境下录制预览流,以保存明亮的视频。

有关详情,请参阅弱光增强

虛擬 MIDI 2.0 裝置

Android 13 已新增使用 USB 連線到使用 USB 連線至 MIDI 2.0 裝置的支援功能,該支援使用通用 MIDI 封包 (UMP) 通訊。Android 15 將 UMP 支援範圍擴及虛擬 MIDI 應用程式,讓撰寫應用程式能夠以虛擬 MIDI 2.0 裝置的形式控制合成器應用程式,就像使用 USB MIDI 2.0 裝置一樣。

連線能力

Android 15 會更新平台,讓應用程式存取最新的通訊內容。

衛星支援

Android 15 继续扩展对卫星连接的平台支持,并添加了一些界面元素,以确保在卫星连接环境中提供一致的用户体验。

应用可以使用 ServiceState.isUsingNonTerrestrialNetwork() 检测设备何时连接到卫星,从而更好地了解为什么全网络服务不可用。此外,Android 15 支持短信和彩信应用以及预加载的 RCS 应用,以便使用卫星连接收发信息。

设备连接到卫星时显示通知。

更流暢的 NFC 體驗

Android 15 正努力让感应式付款体验更加顺畅和可靠,同时继续支持 Android 强大的 NFC 应用生态系统。在受支持的设备上,应用可以请求 NfcAdapter 进入观察模式,在该模式下,设备会监听 NFC 读取器,但不响应 NFC 读取器,同时发送应用的 NFC 服务 PollingFrame 对象进行处理。PollingFrame 对象可用于在首次与 NFC 读取器通信之前进行身份验证,在许多情况下可实现一键交易。

開發人員的工作效率與工具

我們所做的大部分努力都是為了改善效率提升中心,例如 Android StudioJetpack ComposeAndroid Jetpack 程式庫,但我們一直致力於在平台上尋找各種功能,協助您更輕鬆地實現想像。

改善 PDF

Android 15 开发者预览版 2 包含对 PdfRenderer API 重大改进的早期预览版。应用可以整合各种高级功能,例如渲染受密码保护的文件、注解、表单编辑搜索和通过文案进行选择。支持线性 PDF 优化,以加快本地 PDF 的查看速度并减少资源使用量。

针对 PDF 渲染功能的最新更新包括搜索嵌入式 PDF 文件等功能。

PdfRenderer 已移至一个模块,此模块可使用与平台版本无关的 Google Play 系统更新来进行更新,并且我们将通过创建兼容的 API Surface 低于 Android 15 的版本(称为 PdfRendererPreV)来支持在 Android 11(API 级别 30)中更新这些变更。

我们非常重视您对 PdfRenderer API 接口的增强功能的反馈,我们计划通过即将推出的 Android Jetpack 库,让开发者能更轻松地将这些 API 整合到您的应用中。

自動語言切換修正功能

Android 14 增加了设备端音频中的多语言识别功能,可在语言之间自动切换,但这可能会导致单词丢失,尤其是在语言切换时,两种话语之间的停顿较少时。Android 15 添加了额外的控件,可帮助应用根据其用例调整此切换。EXTRA_LANGUAGE_SWITCH_INITIAL_ACTIVE_DURATION_TIME_MILLIS 会将自动切换限制为仅在音频会话开始时进行,而 EXTRA_LANGUAGE_SWITCH_MATCH_SWITCHES 则会在指定次数的切换后停用语言切换。如果您希望自动检测到会话期间只讲一种语言,这些选项特别有用。

精細線條中斷控制項

从 Android 15 开始,TextView 和底层换行符可以将文本的给定部分保留在同一行中,以提高可读性。您可以通过在字符串资源或 createNoBreakSpan 中使用 <nobreak> 标记来利用此换行符自定义功能。同样,您可以使用 <nohyphen> 标记或 createNoHyphenationSpan 避免断字的情况。

例如,以下字符串资源不包含换行符,而是在不希望的位置显示文本“Pixel 8 Pro”进行渲染:

<resources>
    <string name="pixel8pro">The power and brains behind Pixel 8 Pro.</string>
</resources>

相比之下,此字符串资源包含 <nobreak> 标记,该标记会封装短语“Pixel 8 Pro.”并防止换行符:

<resources>
    <string name="pixel8pro">The power and brains behind <nobreak>Pixel 8 Pro.</nobreak></string>
</resources>

这些字符串的呈现方式差异如下图所示:

用于设置一行文本的布局,其中词组“Pixel 8 Pro”未使用 <nobreak> 标记进行换行。
同一行文本的布局,其中词组“Pixel 8 Pro”用 <nobreak> 标记封装。

OpenJDK 17 更新

Android 15 会继续更新 Android 的核心库,以与最新 OpenJDK LTS 版本中的功能保持一致。

其中包含以下主要功能和改进:

这些 API 通过 Google Play 系统更新在超过 10 亿台搭载 Android 12(API 级别 31)及更高版本的设备上进行了更新,让您能够以最新的编程功能为目标平台。

Java 和 OpenJDK 是 Oracle 及/或其关联公司的商标或注册商标。

大螢幕與板型規格

Android 15 可讓應用程式充分運用 Android 的板型規格,包括大螢幕、可折疊式裝置和折疊式裝置。

封面螢幕支援

應用程式可以宣告 Android 15 用來宣告的屬性,以便讓您的 ApplicationActivity 顯示在支援的可滑動裝置小封面螢幕。這些畫面太小,無法視為 Android 應用程式的相容目標,但您的應用程式可以選擇支援這些畫面,藉此在更多地方提供您的應用程式。

效能和電池

Android 會持續專注於提升應用程式的效能和品質。Android 15 導入了新的 API,可提高應用程式工作的執行效率、最佳化應用程式效能,以及收集應用程式的相關深入分析資訊。

ApplicationStartInfo API

在舊版 Android 中,應用程式啟動程序有點複雜。要判斷應用程式內的是從冷、暖還是熱狀態啟動,並不容易。此外,您也很難知道應用程式在各種啟動階段花費的時間,包括建立程序、呼叫 onCreate、繪製第一個影格等。將 Application 類別例項化時,您無法得知應用程式是從廣播、內容供應器、工作、備份、啟動完成、鬧鐘或 Activity 啟動。

Android 15 上的 ApplicationStartInfo API 提供了以上所有功能。甚至可以選擇在流程中加入自己的時間戳記,以在同一位置收集時間資料。除了收集指標,您還可以使用 ApplicationStartInfo 直接最佳化應用程式啟動作業。舉例來說,您可以在應用程式因為廣播訊息而啟動時,避免在 Application 類別中耗費大量成本的 UI 相關程式庫。

應用程式大小詳細資訊

自 Android 8.0(API 级别 26)起,Android 就一直包含 StorageStats.getAppBytes API,该 API 将应用的安装大小汇总为一个字节,这些字节是 APK 大小、从 APK 中提取的文件的大小以及设备上生成的文件(例如预先 (AOT) 编译代码)的总和。就应用的存储空间使用情况而言,此数字并不富有见解。

Android 15 增加了 StorageStats.getAppBytesByDataType([type]) API,可让您深入了解应用如何使用所有空间,包括 APK 文件拆分、AOT 和加速相关代码、dex 元数据、库和引导式配置文件。

改善 SQLite 資料庫

Android 15 introduces new SQLite APIs that expose advanced features from the underlying SQLite engine that target specific performance issues that can manifest in apps.

Developers should consult best practices for SQLite performance to get the most out of their SQLite database, especially when working with large databases or when running latency-sensitive queries.

  • Read-only deferred transactions: when issuing transactions that are read-only (don't include write statements), use beginTransactionReadOnly() and beginTransactionWithListenerReadOnly(SQLiteTransactionListener) to issue read-only DEFERRED transactions. Such transactions can run concurrently with each other, and if the database is in WAL mode, they can run concurrently with IMMEDIATE or EXCLUSIVE transactions.
  • Row counts and IDs: new APIs were added to retrieve the count of changed rows or the last inserted row ID without issuing an additional query. getLastChangedRowCount() returns the number of rows that were inserted, updated, or deleted by the most recent SQL statement within the current transaction, while getTotalChangedRowCount() returns the count on the current connection. getLastInsertRowId() returns the rowid of the last row to be inserted on the current connection.
  • Raw statements: issue a raw SQlite statement, bypassing convenience wrappers and any additional processing overhead that they may incur.

Android 動態效能架構更新

Android 15 continues our investment in the Android Dynamic Performance Framework (ADPF), a set of APIs that allow games and performance intensive apps to interact more directly with power and thermal systems of Android devices. On supported devices, Android 15 will add new ADPF capabilities:

  • A power-efficiency mode for hint sessions to indicate that their associated threads should prefer power saving over performance, great for long-running background workloads.
  • GPU and CPU work durations can both be reported in hint sessions, allowing the system to adjust CPU and GPU frequencies together to best meet workload demands.
  • Thermal headroom thresholds to interpret possible thermal throttling status based on headroom prediction.

To learn more about how to use ADPF in your apps and games, head over to the documentation.

隱私權

Android 15 內含各種功能,可協助應用程式開發人員保護使用者隱私。

螢幕錄影偵測

Android 15 新增了「應用程式支援」,可偵測正在錄影。每次應用程式在螢幕錄影中可見或隱藏時,系統會叫用回呼。如果註冊程序 UID 所擁有的活動受到記錄,系統就會將應用程式視為可見。這麼一來,如果應用程式正在執行機密作業,可以通知使用者系統正在錄製他們的應用程式。

val mCallback = Consumer<Int> { state ->
  if (state == SCREEN_RECORDING_STATE_VISIBLE) {
    // We're being recorded
  } else {
    // We're not being recorded
  }
}

override fun onStart() {
   super.onStart()
   val initialState =
      windowManager.addScreenRecordingCallback(mainExecutor, mCallback)
   mCallback.accept(initialState)
}

override fun onStop() {
    super.onStop()
    windowManager.removeScreenRecordingCallback(mCallback)
}

擴充的 IntentFilter 功能

Android 15 构建了通过 UriRelativeFilterGroup 支持更精确的 Intent 解析,其中包含一组 UriRelativeFilter 对象,这些对象构成了一组必须满足的 Intent 匹配规则,其中包括网址查询参数、网址片段以及屏蔽或排除规则。

您可以使用新的 <uri-relative-filter-group> 标记在 AndroidManifest XML 文件中定义这些规则,也可以选择包含 android:allow 标记。这些标记可以包含使用现有数据标记属性以及新的 android:queryandroid:fragment 属性的 <data> 标记。

下面是 AndroidManifest 语法的示例:

<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data android:scheme="http" />
  <data android:scheme="https" />
  <data android:domain="astore.com" />
  <uri-relative-filter-group>
    <data android:pathPrefix="/auth" />
    <data android:query="region=na" />
  </uri-relative-filter-group>
  <uri-relative-filter-group android:allow="false">
    <data android:pathPrefix="/auth" />
    <data android:query="mobileoptout=true" />
  </uri-relative-filter-group>
  <uri-relative-filter-group android:allow="false">
    <data android:pathPrefix="/auth" />
    <data android:fragmentPrefix="faq" />
  </uri-relative-filter-group>
</intent-filter>

Android 版 Privacy Sandbox

Android 15 將 Android 廣告服務納入最高等級 10,並納入最新版 Android 版 Privacy Sandbox。這是我們開發的新技術,旨在改善使用者隱私,並為行動應用程式提供有效且個人化廣告體驗。如要進一步瞭解 Android 版 Privacy Sandbox 開發人員預覽版和 Beta 版計畫,請參閱隱私權沙箱頁面,瞭解如何踏出第一步。

Health Connect

Android 15 會在 Health Connect by Android 周圍整合 Android 14 擴充功能 10,這是一個安全的集中式平台,可用於管理及分享應用程式收集的健康與健身資料。本次更新在健身營養等方面支援新資料類型。

局部分享螢幕畫面

Android 15 支持局部屏幕共享,因此用户可以仅分享或录制应用窗口,而不是整个设备屏幕。此功能在 Android 14 QPR2 中首次启用,包含 MediaProjection 回调,可让您的应用自定义局部屏幕共享体验。请注意,对于以 Android 14(API 级别 34)或更高版本为目标平台的应用,现在需要针对每个 MediaProjection 捕获会话征得用户同意

安全性

Android 15 有助於提升應用程式的安全性並保護應用程式資料。

使用 fs-verity 保護檔案

Android 15 的 FileIntegrityManager 包含一些可让您利用 Linux 内核中 fs-verity 功能的强大功能的新 API。借助 fs-verity,您可以通过自定义加密签名保护文件,从而确保文件未被篡改或损坏。这有助于增强安全性,防止潜在的恶意软件或未经授权的文件修改,从而损害应用的功能或数据。

使用者體驗

Android 15 可讓應用程式開發人員和使用者進一步控管及彈性設定裝置,以符合自己的需求。

改善「零打擾」規則

AutomaticZenRule lets apps customize Attention Management (Do Not Disturb) rules and decide when to activate or deactivate them. Android 15 greatly enhances these rules with the goal of improving the user experience. The following enhancements are included:

  • Adding types to AutomaticZenRule, allowing the system to apply special treatment to some rules.
  • Adding an icon to AutomaticZenRule, helping to make the modes be more recognizable.
  • Adding a triggerDescription string to AutomaticZenRule that describes the conditions on which the rule should become active for the user.
  • Added ZenDeviceEffects to AutomaticZenRule, allowing rules to trigger things like grayscale display, night mode, or dimming the wallpaper.