Android 15 為開發人員推出了強大的新功能和 API。下列各節總結這些功能,協助您開始使用相關的 API。
如需新增、修改及移除 API 的詳細清單,請參閱 API 差異比較表。如要進一步瞭解新 API,請造訪 Android API 參考資料。系統會醒目顯示新的 API,方便您查看。此外,如要瞭解平台異動可能會影響應用程式的哪些部分,請務必查看 Android 15 鎖定 Android 15 時影響應用程式的行為變更,以及影響所有應用程式 (無論targetSdkVersion
為何) 的行為變更。相機與媒體
Android 15 包含多項功能,可改善相機和媒體體驗,並提供相關工具和硬體,協助創作者在 Android 平台上實現願景。
應用程式內相機控制選項
Android 15 新增了擴充功能,讓你在支援的裝置上進一步控管相機硬體及其演算法:
HDR 進步空間控制
Android 15 chooses HDR headroom that is appropriate for the underlying device
capabilities and bit-depth of the panel. For pages that have lots of SDR
content, such as a messaging app displaying a single HDR thumbnail, this
behavior can end up adversely influencing the perceived brightness of the SDR
content. Android 15 lets you control the HDR headroom with
setDesiredHdrHeadroom
to strike a balance between SDR
and HDR content.
音量控制
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 introduces Low Light Boost, a new auto-exposure mode available to both Camera 2 and the night mode camera extension. Low Light Boost adjusts the exposure of the Preview stream in low-light conditions. This is different from how the night mode camera extension creates still images, because night mode combines a burst of photos to create a single, enhanced image. While night mode works very well for creating a still image, it can't create a continuous stream of frames, but Low Light Boost can. Thus, Low Light Boost enables new camera capabilities, such as:
- Providing an enhanced image preview, so users are better able to frame their low-light pictures
- Scanning QR codes in low light
If you enable Low Light Boost, it automatically turns on when there's a low light level, and turns off when there's more light.
Apps can record off the Preview stream in low-light conditions to save a brightened video.
For more information, see Low Light Boost.
虛擬 MIDI 2.0 裝置
Android 13 added support for connecting to MIDI 2.0 devices using USB, which communicate using Universal MIDI Packets (UMP). Android 15 extends UMP support to virtual MIDI apps, enabling composition apps to control synthesizer apps as a virtual MIDI 2.0 device just like they would with an USB MIDI 2.0 device.
連線能力
Android 15 會更新平台,讓應用程式存取最新的通訊內容。
衛星支援
Android 15 continues to extend platform support for satellite connectivity and includes some UI elements to ensure a consistent user experience across the satellite connectivity landscape.
Apps can use ServiceState.isUsingNonTerrestrialNetwork()
to
detect when a device is connected to a satellite, giving them more awareness of
why full network services might be unavailable. Additionally, Android 15
provides support for SMS and MMS apps as well as preloaded RCS apps to use
satellite connectivity for sending and receiving messages.
更流暢的 NFC 體驗
Android 15 is working to make the tap to pay experience more seamless and
reliable while continuing to support Android's robust NFC app ecosystem. On
supported devices, apps can request the NfcAdapter
to enter
observe mode, where the device listens but doesn't respond to NFC
readers, sending the app's NFC service PollingFrame
objects to process. The PollingFrame
objects can be used to auth
ahead of the first communication to the NFC reader, allowing for a one tap
transaction in many cases.
錢包角色
Android 15 introduces a new Wallet role that allows tighter integration with the user's preferred wallet app. This role replaces the NFC default contactless payment setting. Users can manage the Wallet role holder by navigating to Settings > Apps > Default Apps.
The Wallet role is used when routing NFC taps for AIDs registered in the payment category. Taps always go to the Wallet role holder unless another app that is registered for the same AID is running in the foreground.
This role is also used to determine where the Wallet QuickAccess tile should go when activated. When the role is set to "None", the QuickAccess tile isn't available and payment category NFC taps are only delivered to the foreground app.
開發人員的工作效率與工具
我們所做的大部分努力都是為了改善效率提升中心,例如 Android Studio、Jetpack Compose 和 Android Jetpack 程式庫,但我們一直致力於在平台上尋找各種功能,協助您更輕鬆地實現想像。
改善 PDF
Android 15 Developer Preview 2 includes an early preview of substantial
improvements to the PdfRenderer
APIs. Apps can incorporate
advanced features such as rendering password-protected files,
annotations, form editing, searching, and
selection with copy. Linearized PDF optimizations are supported to
speed local PDF viewing and reduce resource use.
The PdfRenderer
has been moved to a module that can be updated using Google
Play system updates independent of the platform release, and we're supporting
these changes back to Android 11 (API level 30) by creating a compatible
pre-Android 15 version of the API surface, called
PdfRendererPreV
.
We value your feedback on the enhancements we've made to the PdfRenderer
API
surface, and we plan to make it even easier to incorporate these APIs into your
app with an upcoming Android Jetpack library.
自動語言切換修正功能
Android 14 added on-device, multi-language recognition in audio with automatic
switching between languages, but this can cause words to get dropped,
especially when languages switch with less of a pause between the two
utterances. Android 15 adds additional controls to help apps tune this switching
to their use case.
EXTRA_LANGUAGE_SWITCH_INITIAL_ACTIVE_DURATION_TIME_MILLIS
confines the automatic switching to the beginning of the audio session, while
EXTRA_LANGUAGE_SWITCH_MATCH_SWITCHES
deactivates the
language switching after a defined number of switches. These options are
particularly useful if you expect that there will be a single language spoken
during the session that should be autodetected.
精細線條中斷控制項
Starting in Android 15, a TextView
and the underlying
line breaker can preserve the given portion of text in the same line to improve
readability. You can take advantage of this line break customization by using
the <nobreak>
tag in string resources or
createNoBreakSpan
. Similarly, you can preserve words from
hyphenation by using the <nohyphen>
tag or
createNoHyphenationSpan
.
For example, the following string resource doesn't include a line break, and renders with the text "Pixel 8 Pro." breaking in an undesirable place:
<resources>
<string name="pixel8pro">The power and brains behind Pixel 8 Pro.</string>
</resources>
In contrast, this string resource includes the <nobreak>
tag, which wraps the
phrase "Pixel 8 Pro." and prevents line breaks:
<resources>
<string name="pixel8pro">The power and brains behind <nobreak>Pixel 8 Pro.</nobreak></string>
</resources>
The difference in how these strings are rendered is shown in the following images:
OpenJDK 17 更新
Android 15 continues the work of refreshing Android's core libraries to align with the features in the latest OpenJDK LTS releases.
The following key features and improvements are included:
- Quality-of-life improvements around NIO buffers
- Streams
- Additional
math
andstrictmath
methods util
package updates including sequencedcollection
,map
, andset
ByteBuffer
support inDeflater
- Security updates such as
X500PrivateCredential
and security key updates
These APIs are updated on over a billion devices running Android 12 (API level 31) and higher through Google Play System updates, so you can target the latest programming features.
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
大螢幕與板型規格
Android 15 可讓應用程式充分運用 Android 的板型規格,包括大螢幕、可折疊式裝置和折疊式裝置。
封面螢幕支援
Your app can declare a property that Android 15 uses to
allow your Application
or Activity
to be presented on the small cover
screens of supported flippable devices. These screens are too small to be
considered as compatible targets for Android apps to run on, but your app can
opt in to supporting them, making your app available in more places.
效能和電池
Android 會持續專注於提升應用程式的效能和品質。Android 15 導入了新的 API,可提高應用程式工作的執行效率、最佳化應用程式效能,以及收集應用程式的相關深入分析資訊。
ApplicationStartInfo API
In previous versions of Android, app startup has been a bit of a mystery. It was
challenging to determine within your app whether it started from a cold, warm,
or hot state. It was also difficult to know how long your app spent during the
various launch phases: forking the process, calling onCreate
, drawing the
first frame, and more. When your Application
class was instantiated, you had no
way of knowing whether the app started from a broadcast, a content provider, a
job, a backup, boot complete, an alarm, or an Activity
.
The ApplicationStartInfo
API on Android 15 provides
all of this and more. You can even choose to add your own timestamps into the
flow to help collect timing data in one place. In addition to collecting
metrics, you can use ApplicationStartInfo
to help directly optimize app
startup; for example, you can eliminate the costly instantiation of UI-related
libraries within your Application
class when your app is starting up due to a
broadcast.
應用程式大小詳細資訊
Since Android 8.0 (API level 26), Android has included the
StorageStats.getAppBytes
API that summarizes the installed
size of an app as a single number of bytes, which is a sum of the APK size, the
size of files extracted from the APK, and files that were generated on the
device such as ahead-of-time (AOT) compiled code. This number is not very
insightful in terms of how your app is using storage.
Android 15 adds the
StorageStats.getAppBytesByDataType([type])
API, which lets
you get insight into how your app is using up all that space, including APK file
splits, AOT and speedup related code, dex metadata, libraries, and guided
profiles.
改善 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()
andbeginTransactionWithListenerReadOnly(SQLiteTransactionListener)
to issue read-onlyDEFERRED
transactions. Such transactions can run concurrently with each other, and if the database is in WAL mode, they can run concurrently withIMMEDIATE
orEXCLUSIVE
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, whilegetTotalChangedRowCount()
returns the count on the current connection.getLastInsertRowId()
returns therowid
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 持續投資於 Android 動態效能架構 (ADPF),這是一組 API,可讓遊戲和效能密集的應用程式直接與 Android 裝置的電源和熱能系統互動。在支援的裝置上,Android 15 會新增 ADPF 功能:
- 提示工作階段的「省電模式」,用來表示相關聯的執行緒偏好省電而非效能,非常適合用於長時間執行的背景工作負載。
- 無論是在提示工作階段中,都能回報 GPU 和 CPU 工作持續時間,讓系統據此調整 CPU 和 GPU 頻率,以滿足工作負載需求。
- 熱力上升門檻:根據進步空間預測結果解釋可能的熱節保護狀態。
如要進一步瞭解如何在應用程式和遊戲中使用 ADPF,請參閱說明文件。
隱私權
Android 15 內含各種功能,可協助應用程式開發人員保護使用者隱私。
螢幕錄影偵測
Android 15 adds support for apps to detect that they are being recorded. A callback is invoked whenever the app transitions between being visible or invisible within a screen recording. An app is considered visible if activities owned by the registering process's UID are being recorded. This way, if your app is performing a sensitive operation, you can inform the user that they're being recorded.
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 builds in support for more precise Intent
resolution through
UriRelativeFilterGroup
, which contains a set of
UriRelativeFilter
objects that form a set of Intent
matching rules that must each be satisfied, including URL query parameters, URL
fragments, and blocking or exclusion rules.
These rules can be defined in the AndroidManifest
XML file with the new
<uri-relative-filter-group>
tag, which can optionally include an
android:allow
tag. These tags can contain <data>
tags that use existing data
tag attributes as well as the new android:query
and android:fragment
attributes.
Here's an example of the AndroidManifest
syntax:
<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 integrates Android 14 extensions 10 around Health Connect by Android, a secure and centralized platform to manage and share app-collected health and fitness data. This update adds support for new data types across fitness, nutrition, and more.
局部分享螢幕畫面
Android 15 supports partial screen sharing so users can share or record just an
app window rather than the entire device screen. This feature, first enabled in
Android 14 QPR2, includes
MediaProjection
callbacks that allow your app
to customize the partial screen sharing experience. Note that for apps targeting
Android 14 (API level 34) or higher,
user consent is now required for each
MediaProjection
capture session.
安全性
Android 15 有助於提升應用程式的安全性並保護應用程式資料。
使用 fs-verity 保護檔案
Android 15's FileIntegrityManager
includes new APIs
that tap into the power of the fs-verity
feature in the Linux kernel. With fs-verity, files can be protected by custom
cryptographic signatures, helping you ensure they
haven't been tampered with or corrupted. This leads to
enhanced security, protecting against potential malware or unauthorized file
modifications that could compromise your app's functionality or data.
使用者體驗
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 toAutomaticZenRule
that describes the conditions on which the rule should become active for the user. - Added
ZenDeviceEffects
toAutomaticZenRule
, allowing rules to trigger things like grayscale display, night mode, or dimming the wallpaper.