功能與 API 總覽

Android 15 為開發人員推出了強大的功能和 API。以下各節會簡要說明這些功能,協助您開始使用相關 API。

如需新增、修改及移除 API 的詳細清單,請參閱 API 差異比較表。如要進一步瞭解新增的 API,請參閱 Android API 參考資料 - 針對 Android 15,請尋找 API 級別 35 中新增的 API。如要瞭解平台變更可能對應用程式造成的影響,請務必查看指定 Android 15 的應用程式所有應用程式的 Android 15 行為變更。

相機和媒體

Android 15 包含多種功能,可提升相機和媒體體驗,並提供工具和硬體,協助創作者在 Android 上實現創意。

如要進一步瞭解 Android 媒體和相機的最新功能和開發人員解決方案,請觀看 Google I/O 的「打造現代 Android 媒體和相機體驗」演講。

低光源增強

Android 15 引入了弱光增强功能,这是一种自动曝光模式,适用于 Camera 2夜间模式相机扩展。“弱光增强”功能可在光线昏暗的环境下调整预览画面的曝光度。这与夜间模式相机扩展程序创建静态图片的方式不同,因为夜间模式会将一系列照片组合起来,以创建一张经过增强的单张图片。虽然夜间模式非常适合拍摄静态图片,但无法创建连续的帧流,而“低光增强”功能可以。因此,弱光增强功能可启用相机功能,例如:

  • 提供增强型图片预览,以便用户更好地取景拍摄低光照片
  • 在光线不足的情况下扫描二维码

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

应用可以在光线昏暗的环境下录制预览画面,以保存经过亮度提升的视频。

如需了解详情,请参阅弱光增强

應用程式內攝影機控制選項

Android 15 添加了一个扩展程序,可让您更好地控制支持的设备上的相机硬件及其算法:

  • 高级闪光灯强度调整:在拍摄图片时,可在 SINGLETORCH 模式下精确控制闪光灯强度。

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.

The brightness of SDR UI elements on the left screen appears to be more uniform than the brightness on the right screen, which simulates possible headroom issues when HDR and SDR content are mixed. By adjusting the HDR headroom, you can achieve a better balance between the SDR and HDR content.

音量控制

Android 15 開始支援 CTA-2075 音量標準,協助您 可避免音訊音量不一致的情況,同時確保使用者不必一直 調整音量。系統會利用輸出裝置 (耳機和喇叭) 的已知特性,以及 AAC 音訊內容提供的音量中繼資料,智慧調整音訊音量和動態範圍壓縮等級。

如要啟用這項功能,請務必確保檔案含有音量中繼資料 您的 AAC 內容,並在應用程式中啟用平台功能。為此,您 透過以下方式將 LoudnessCodecController 物件執行個體化: 呼叫其 create 工廠方法,並與音訊 來自相關聯 AudioTrack 的工作階段 ID;本 系統就會開始自動套用音訊更新您可以傳遞 OnLoudnessCodecUpdateListener,藉此修改或篩選音量參數,再套用至 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 也會更新,使用 透過 LoudnessCodecController API 完美整合應用程式。

虛擬 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.

更有效率的 AV1 軟體解碼

dav1d 標誌

dav1d 是 VideoLAN 推出的熱門 AV1 軟體解碼器,適用於不支援硬體 AV1 解碼功能的 Android 裝置。dav1d 的效能比舊版 AV1 軟體解碼器高出 3 倍,可讓更多使用者 (包括部分低階和中階裝置) 播放 HD AV1 影片。

您的應用程式必須透過名稱 "c2.android.av1-dav1d.decoder" 呼叫 dav1d,才能選擇使用 dav1d。在後續更新中,dav1d 將成為預設的 AV1 軟體解碼器。這項支援功能已標準化,並向後移植至接收 Google Play 系統更新的 Android 11 裝置。

開發人員工作效率和工具

我們致力於提升開發人員的工作效率,因此大部分工作都圍繞著 Android StudioJetpack ComposeAndroid Jetpack 程式庫等工具進行,但我們也不斷尋找平台上的各種方法,協助您更輕鬆地實現願景。

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:

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.

PDF 改善項目

Android 15 對 PdfRenderer 進行了大幅改善。 相互整合應用程式可導入轉譯等進階功能 受密碼保護的檔案、註解、表單編輯搜尋選取副本。支援線性化 PDF 最佳化功能,可加快本機 PDF 檢視速度並減少資源使用量。Jetpack PDF 程式庫會使用這些 API,簡化在應用程式中新增 PDF 檢視功能的程序。

以下是最新的 PDF 轉譯功能更新項目,這些功能包括: 搜尋內嵌的 PDF 檔案

PdfRenderer 已移至可透過 Google Play 系統更新進行更新的模組,不受平台版本影響。我們會透過建立與 Android 15 以下版本相容的 API 途徑 (稱為 PdfRendererPreV),將這些變更回溯至 Android 11 (API 級別 30)。

自動切換語言的改良功能

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.

改良的 OpenType 變數字型 API

Android 15 improves the usability of the OpenType variable font. You can create a FontFamily instance from a variable font without specifying weight axes with the buildVariableFamily API. The text renderer overrides the value of wght axis to match the displaying text.

Using the API simplifies the code for creating a Typeface considerably:

Kotlin

val newTypeface = Typeface.CustomFallbackBuilder(
            FontFamily.Builder(
                Font.Builder(assets, "RobotoFlex.ttf").build())
                    .buildVariableFamily())
    .build()

Java

Typeface newTypeface = Typeface.CustomFallbackBuilder(
            new FontFamily.Builder(
                new Font.Builder(assets, "RobotoFlex.ttf").build())
                    .buildVariableFamily())
    .build();

Previously, to create the same Typeface, you would need much more code:

Kotlin

val oldTypeface = Typeface.CustomFallbackBuilder(
            FontFamily.Builder(
                Font.Builder(assets, "RobotoFlex.ttf")
                    .setFontVariationSettings("'wght' 400")
                    .setWeight(400)
                    .build())
                .addFont(
                    Font.Builder(assets, "RobotoFlex.ttf")
                        .setFontVariationSettings("'wght' 100")
                        .setWeight(100)
                        .build()
                )
                .addFont(
                    Font.Builder(assets, "RobotoFlex.ttf")
                        .setFontVariationSettings("'wght' 200")
                        .setWeight(200)
                        .build()
                )
                .addFont(
                    Font.Builder(assets, "RobotoFlex.ttf")
                        .setFontVariationSettings("'wght' 300")
                        .setWeight(300)
                        .build()
                )
                .addFont(
                    Font.Builder(assets, "RobotoFlex.ttf")
                        .setFontVariationSettings("'wght' 500")
                        .setWeight(500)
                        .build()
                )
                .addFont(
                    Font.Builder(assets, "RobotoFlex.ttf")
                        .setFontVariationSettings("'wght' 600")
                        .setWeight(600)
                        .build()
                )
                .addFont(
                    Font.Builder(assets, "RobotoFlex.ttf")
                        .setFontVariationSettings("'wght' 700")
                        .setWeight(700)
                        .build()
                )
                .addFont(
                    Font.Builder(assets, "RobotoFlex.ttf")
                        .setFontVariationSettings("'wght' 800")
                        .setWeight(800)
                        .build()
                )
                .addFont(
                    Font.Builder(assets, "RobotoFlex.ttf")
                        .setFontVariationSettings("'wght' 900")
                        .setWeight(900)
                        .build()
                ).build()
        ).build()

Java

Typeface oldTypeface = new Typeface.CustomFallbackBuilder(
    new FontFamily.Builder(
        new Font.Builder(assets, "RobotoFlex.ttf")
            .setFontVariationSettings("'wght' 400")
            .setWeight(400)
            .build()
    )
    .addFont(
        new Font.Builder(assets, "RobotoFlex.ttf")
            .setFontVariationSettings("'wght' 100")
            .setWeight(100)
            .build()
    )
    .addFont(
        new Font.Builder(assets, "RobotoFlex.ttf")
            .setFontVariationSettings("'wght' 200")
            .setWeight(200)
            .build()
    )
    .addFont(
        new Font.Builder(assets, "RobotoFlex.ttf")
            .setFontVariationSettings("'wght' 300")
            .setWeight(300)
            .build()
    )
    .addFont(
        new Font.Builder(assets, "RobotoFlex.ttf")
            .setFontVariationSettings("'wght' 500")
            .setWeight(500)
            .build()
    )
    .addFont(
        new Font.Builder(assets, "RobotoFlex.ttf")
            .setFontVariationSettings("'wght' 600")
            .setWeight(600)
            .build()
    )
    .addFont(
        new Font.Builder(assets, "RobotoFlex.ttf")
            .setFontVariationSettings("'wght' 700")
            .setWeight(700)
            .build()
    )
    .addFont(
        new Font.Builder(assets, "RobotoFlex.ttf")
            .setFontVariationSettings("'wght' 800")
            .setWeight(800)
            .build()
    )
    .addFont(
        new Font.Builder(assets, "RobotoFlex.ttf")
            .setFontVariationSettings("'wght' 900")
            .setWeight(900)
            .build()
    )
    .build()
).build();

Here's an example of how a Typeface created with both the old and new APIs renders:

An example of how Typeface rendering differs using new and old
APIs

In this example, the Typeface created with the old API doesn't have the capability to create accurate font weights for the 350, 450, 550 and 650 Font instances, so the renderer falls back to the closest weight. So in this case, 300 is rendered instead of 350, 400 is rendered instead of 450, and so on. By contrast, the Typeface created with the new APIs dynamically creates a Font instance for a given weight, so accurate weights are rendered for 350, 450, 550, and 650 as well.

精細的換行符號控制

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:

Layout for a line of text where the phrase "Pixel 8 Pro." isn't wrapped using a <nobreak> tag.
Layout for the same line of text where the phrase "Pixel 8 Pro." is wrapped using a <nobreak> tag.

封存應用程式

Android and Google Play announced support for app archiving last year, allowing users to free up space by partially removing infrequently used apps from the device that were published using Android App Bundle on Google Play. Android 15 includes OS level support for app archiving and unarchiving, making it easier for all app stores to implement it.

Apps with the REQUEST_DELETE_PACKAGES permission can call the PackageInstaller requestArchive method to request archiving an installed app package, which removes the APK and any cached files, but persists user data. Archived apps are returned as displayable apps through the LauncherApps APIs; users will see a UI treatment to highlight that those apps are archived. If a user taps on an archived app, the responsible installer will get a request to unarchive it, and the restoration process can be monitored by the ACTION_PACKAGE_ADDED broadcast.

使用开发者选项在设备上启用 16 KB 模式

切换以 16KB 页面大小启动设备开发者选项,以在 16 KB 模式下启动设备。

从 Android 15 QPR1 开始,您可以使用某些设备上提供的开发者选项,以 16 KB 模式启动设备并执行设备端测试。在使用开发者选项之前,请依次前往设置 > 系统 > 软件更新,并应用所有可用的更新。

此开发者选项适用于以下设备:

  • Pixel 8 和 8 Pro(搭载 Android 15 QPR1 或更高版本)

  • Pixel 8a(搭载 Android 15 QPR1 或更高版本)

  • Pixel 9、9 Pro 和 9 Pro XL(搭载 Android 15 QPR2 Beta 2 或更高版本)

圖形

Android 15 帶來最新的圖像改善項目,包括 ANGLE 和 Canvas 圖像系統的增強功能。

更新 Android 的 GPU 存取權

Vulkan 標誌

與早期核心作業系統會在單一 CPU 上執行,並使用以固定函式管道為基礎的 API 存取 GPU 不同,Android 硬體已大幅進化。自 Android 7.0 (API 級別 24) 起,NDK 就提供 Vulkan® 圖形 API,其中包含低階抽象化功能,可更貼近現代 GPU 硬體、更有效地支援多個 CPU 核心,並減少 CPU 驅動程式額外負擔,進而提升應用程式效能。所有新型遊戲引擎都支援 Vulkan。

Vulkan 是 Android 對 GPU 的偏好介面。因此,Android 15 包含 ANGLE 做為可選的圖層,可在 Vulkan 上執行 OpenGL® ES。改用 ANGLE 可將 Android OpenGL 實作標準化,進而改善相容性,在某些情況下還能提升效能。您可以在 Android 15 上依序前往「設定」->「系統」->「開發人員選項」->「實驗功能:啟用 ANGLE」,啟用開發人員選項,藉此使用 ANGLE 測試 OpenGL ES 應用程式的穩定性和效能。

Android ANGLE 的 Vulkan 時程表

Android GPU API 即將異動的藍圖。

為了簡化 GPU 堆疊,我們日後會在更多新裝置上提供 ANGLE 做為 GL 系統驅動程式,並預期 OpenGL/ES 日後只會透過 ANGLE 提供。不過,我們計劃繼續在所有裝置上支援 OpenGL ES

建議採取的後續步驟

使用開發人員選項選取 OpenGL ES 的 ANGLE 驅動程式,並測試應用程式。對於新專案,我們強烈建議使用 Vulkan 開發 C/C++。

Canvas 改善項目

Android 15 continues our modernization of Android's Canvas graphics system with additional capabilities:

  • Matrix44 provides a 4x4 matrix for transforming coordinates that should be used when you want to manipulate the canvas in 3D.
  • clipShader intersects the current clip with the specified shader, while clipOutShader sets the clip to the difference of the current clip and the shader, each treating the shader as an alpha mask. This supports the drawing of complex shapes efficiently.

效能和電池

Android 持續致力於協助您提升應用程式的效能和品質。Android 15 導入的 API 可協助您更有效率地執行應用程式中的工作、提升應用程式效能,以及收集應用程式的洞察資訊。

如要瞭解省電最佳做法、如何偵錯網路和耗電量,以及我們如何在 Android 15 和近期 Android 版本中提升背景作業的省電效率,請參閱 Google I/O 的「提升 Android 背景作業的省電效率」演講。

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.

應用程式管理的剖析

Android 15 includes the ProfilingManager class, which lets you collect profiling information from within your app such as heap dumps, heap profiles, stack sampling, and more. It provides a callback to your app with a supplied tag to identify the output file, which is delivered to your app's files directory. The API does rate limiting to minimize the performance impact.

To simplify constructing profiling requests in your app, we recommend using the corresponding Profiling AndroidX API, available in Core 1.15.0-rc01 or higher.

SQLite 資料庫改善項目

Android 15 introduces SQLite APIs that expose advanced features from the underlying SQLite engine that target specific performance issues that can manifest in apps. These APIs are included with the update of SQLite to version 3.44.3.

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: 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 adds 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 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 <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 android:query and android:fragment attributes.

Here's an example of the AndroidManifest syntax:

<intent-filter android:autoVerify="true">
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.BROWSABLE" />
  <category android:name="android.intent.category.DEFAULT" />
  <data android:scheme="http" />
  <data android:scheme="https" />
  <data android:host="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>

私人空間

可通过解锁和锁定私密空间,在设备上显示或隐藏敏感应用。

借助私密空间,用户可以在设备上创建一个单独的空间,在额外的身份验证层保护下,防止敏感应用遭到窥探。私密空间使用单独的用户个人资料。用户可以选择使用设备锁定方式或为私密空间使用单独的锁定方式。

私密空间中的应用会显示在启动器的单独容器中,并且当私密空间处于锁定状态时,这些应用不会显示在“最近用过”视图、通知、“设置”和其他应用中。用户生成的内容和下载的内容(例如媒体内容或文件)以及账号在私密空间和主空间之间是分开的。在私密空间处于解锁状态时,您可以使用系统 Sharesheet照片选择器向应用授予对各个空间中内容的访问权限。

用户无法将现有应用及其数据移至私密空间。相反,用户可以在私密空间中选择安装选项,以便使用他们偏好的任意应用商店安装应用。私密空间中的应用会作为主空间中任何应用的单独副本进行安装(同一应用的新副本)。

当用户锁定私密空间时,系统会停止该个人资料。在个人资料停止运行时,私密空间中的应用将不再处于活动状态,无法执行前台或后台活动,包括显示通知。

我们建议您使用私密空间测试应用,以确保应用能按预期运行,尤其是当您的应用属于以下某一类别时:

查詢「所選相片存取權」的最新使用者選取項目

Apps can now highlight only the most-recently-selected photos and videos when partial access to media permissions is granted. This feature can improve the user experience for apps that frequently request access to photos and videos. To use this feature in your app, enable the QUERY_ARG_LATEST_SELECTION_ONLY argument when querying MediaStore through ContentResolver.

Kotlin

val externalContentUri = MediaStore.Files.getContentUri("external")

val mediaColumns = arrayOf(
   FileColumns._ID,
   FileColumns.DISPLAY_NAME,
   FileColumns.MIME_TYPE,
)

val queryArgs = bundleOf(
   // Return only items from the last selection (selected photos access)
   QUERY_ARG_LATEST_SELECTION_ONLY to true,
   // Sort returned items chronologically based on when they were added to the device's storage
   QUERY_ARG_SQL_SORT_ORDER to "${FileColumns.DATE_ADDED} DESC",
   QUERY_ARG_SQL_SELECTION to "${FileColumns.MEDIA_TYPE} = ? OR ${FileColumns.MEDIA_TYPE} = ?",
   QUERY_ARG_SQL_SELECTION_ARGS to arrayOf(
       FileColumns.MEDIA_TYPE_IMAGE.toString(),
       FileColumns.MEDIA_TYPE_VIDEO.toString()
   )
)

Java

Uri externalContentUri = MediaStore.Files.getContentUri("external");

String[] mediaColumns = {
    FileColumns._ID,
    FileColumns.DISPLAY_NAME,
    FileColumns.MIME_TYPE
};

Bundle queryArgs = new Bundle();
queryArgs.putBoolean(MediaStore.QUERY_ARG_LATEST_SELECTION_ONLY, true);
queryArgs.putString(MediaStore.QUERY_ARG_SQL_SORT_ORDER, FileColumns.DATE_ADDED + " DESC");
queryArgs.putString(MediaStore.QUERY_ARG_SQL_SELECTION, FileColumns.MEDIA_TYPE + " = ? OR " + FileColumns.MEDIA_TYPE + " = ?");
queryArgs.putStringArray(MediaStore.QUERY_ARG_SQL_SELECTION_ARGS, new String[] {
    String.valueOf(FileColumns.MEDIA_TYPE_IMAGE),
    String.valueOf(FileColumns.MEDIA_TYPE_VIDEO)
});

Android 版 Privacy Sandbox

Android 15 包含最新的 Android 广告服务扩展,其中包含最新版本的 Privacy Sandbox on Android。我们一直致力于开发可更好地保护用户隐私,并为移动应用打造高效的个性化广告体验的技术,此次添加新功能就是其中的一项举措。我们的 Privacy Sandbox 页面详细介绍了 Privacy Sandbox on Android 开发者预览版和 Beta 版计划,可帮助您上手使用。

Health Connect

Android 15 集成了与 Health Connect by Android 相关的最新扩展程序。Health Connect by Android 是一个安全的集中式平台,可用于管理和共享应用收集的健康与健身数据。此次更新 增加了对健身营养、体表温度、训练计划等。

体表温度追踪功能让用户可以更精确地存储和分享体表温度 来自穿戴式设备或其他跟踪设备的体温数据。

训练计划是一种结构化的锻炼计划,可帮助用户实现健身目标。训练计划支持各种完成和表现目标:

如需详细了解 Android 中 Health Connect 的最新更新,请参阅 利用 Android 打造自适应体验 健康演讲。

應用程式分享螢幕畫面

Android 15 supports app 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 app screen sharing experience. Note that for apps targeting Android 14 (API level 34) or higher, user consent is required for each MediaProjection capture session.

使用者體驗和系統 UI

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

如要進一步瞭解如何運用 Android 15 的最新改良功能,提升應用程式的使用者體驗,請觀看 Google I/O 的「改善 Android 應用程式的使用者體驗」演講。

使用 Generated Previews API 取得更豐富的小工具預覽畫面

Before Android 15, the only way to provide widget picker previews was to specify a static image or layout resource. These previews often differ significantly from the look of the actual widget when it is placed on the home screen. Also, static resources can't be created with Jetpack Glance, so a Glance developer had to screenshot their widget or create an XML layout to have a widget preview.

Android 15 adds support for generated previews. This means that app widget providers can generate RemoteViews to use as the picker preview, instead of a static resource.

Apps can provide Remote Views to the Widget Picker, so they can update the content in the picker to be more representative of what the user will see.

Push API

Apps can provide generated previews through a push API. Apps can provide previews at any point in their lifecycle, and don't receive an explicit request from the host to provide previews. Previews are persisted in AppWidgetService, and hosts can request them on-demand. The following example loads an XML widget layout resource and sets it as the preview:

AppWidgetManager.getInstance(appContext).setWidgetPreview(
   ComponentName(
       appContext,
       SociaLiteAppWidgetReceiver::class.java
   ),
   AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN,
   RemoteViews("com.example", R.layout.widget_preview)
)

The expected flow is:

  1. At any time, the widget provider calls setWidgetPreview. The provided previews are persisted in AppWidgetService with other provider info.
  2. setWidgetPreview notifies hosts of an updated preview through the AppWidgetHost.onProvidersChanged callback. In response, the widget host reloads all of its provider information.
  3. When displaying a widget preview, the host checks AppWidgetProviderInfo.generatedPreviewCategories, and if the chosen category is available, calls AppWidgetManager.getWidgetPreview to return the saved preview for this provider.

When to call setWidgetPreview

Because there is no callback to provide previews, apps can choose to send previews at any point when they are running. How often to update the preview depends on the widget's use case.

The following list describes the two main categories of preview use cases:

  • Providers that show real data in their widget previews, such as personalized or recent information. These providers can set the preview once the user has signed in or has done initial configuration in their app. After this, they can set up a periodic task to update the previews at their chosen cadence. Examples of this type of widget could be a photo, calendar, weather or news widget.
  • Providers that show static information in previews or quick-action widgets that don't display any data. These providers can set previews once, when the app first launches. Examples of this type of widget include a drive quick actions widget or chrome shortcuts widget.

Some providers might show static previews on the hub mode picker, but real information on the homescreen picker. These providers should follow the guidance for both of these use cases to set previews.

子母畫面

Android 15 introduces changes in Picture-in-Picture (PiP) ensuring an even smoother transition when entering into PiP mode. This will be beneficial for apps having UI elements overlaid on top of their main UI, which goes into PiP.

Developers use the onPictureInPictureModeChanged callback to define logic that toggles the visibility of the overlaid UI elements. This callback is triggered when the PiP enter or exit animation is completed. Beginning in Android 15, the PictureInPictureUiState class includes another state.

With this UI state, apps targeting Android 15 (API level 35) will observe the Activity#onPictureInPictureUiStateChanged callback being invoked with isTransitioningToPip() as soon as the PiP animation starts. There are many UI elements that are not relevant for the app when it is in PiP mode, for example views or layout that include information such as suggestions, upcoming video, ratings, and titles. When the app goes to PiP mode, use the onPictureInPictureUiStateChanged callback to hide these UI elements. When the app goes to full screen mode from the PiP window, use onPictureInPictureModeChanged callback to unhide these elements, as shown in the following examples:

override fun onPictureInPictureUiStateChanged(pipState: PictureInPictureUiState) {
        if (pipState.isTransitioningToPip()) {
          // Hide UI elements
        }
    }
override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean) {
        if (isInPictureInPictureMode) {
          // Unhide UI elements
        }
    }

This quick visibility toggle of irrelevant UI elements (for a PiP window) helps ensure a smoother and flicker-free PiP enter animation.

更完善的「零打擾」規則

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.

為通知管道設定 VibrationEffect

Android 15 支援使用 NotificationChannel.setVibrationEffect 為特定管道設定豐富的震動效果,讓使用者不必查看裝置,就能區分不同類型的通知。

媒體投影狀態列晶片和自動停止

媒体投放可能会泄露用户的私密信息。一个醒目的新状态栏条状标签可让用户了解任何正在进行的屏幕投影。用户可以点按该条状标签停止投屏、共享或录制屏幕。此外,为了提供更直观的用户体验,当设备屏幕锁定后,所有正在进行的屏幕投影都会自动停止。

用於螢幕分享、投放和錄製的狀態列方塊。

大螢幕和板型規格

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

改善大螢幕多工處理功能

Android 15 可讓使用者在大螢幕裝置上更妥善地進行多工處理。適用對象 舉例來說,使用者可以儲存喜愛的分割畫面應用程式組合,以便快速 ,並將工作列固定在畫面上,即可快速切換應用程式。也就是說 確保應用程式會自動調適,比以往更重要。

Google I/O 大會建構可自動調整的 Android 環境 應用程式以及使用 Material 3 建構使用者介面 自動調整程式庫 這能幫助您,而我們的說明文件也更勝以往,能進一步協助您運用大型語言設計 螢幕

支援封面螢幕

您的应用可以声明一个属性,Android 15 会使用该属性来允许您的 ApplicationActivity 显示在受支持的可翻转设备的小封面屏幕上。这些屏幕太小,无法被视为适合运行 Android 应用的兼容目标平台,但您的应用可以选择支持它们,从而让您的应用在更多平台上可用。

連線能力

Android 15 更新了平台,讓您的應用程式能使用通訊和無線技術的最新進展。

衛星支援

Android 15 持續擴大平台支援範圍,包括衛星連線,以及 包含一些 UI 元素,確保 衛星連線環境。

應用程式可以使用 ServiceState.isUsingNonTerrestrialNetwork() 執行下列操作: 會偵測裝置是否與衛星連線 可能無法使用完整網路服務的原因此外,Android 15 支援簡訊和多媒體訊息應用程式,以及預先載入的 RCS 應用程式 可以收發訊息的衛星連線。

裝置連線至衛星時,系統會顯示通知。

更流暢的 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.

In addition, apps can register a filter on supported devices so they can be notified of polling loop activity, which allows for smooth operation with multiple NFC-aware applications.

錢包角色

Android 15 introduces a 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 Quick Access tile should go when activated. When the role is set to "None", the Quick Access tile isn't available and payment category NFC taps are only delivered to the foreground app.

安全性

Android 15 可協助您提升應用程式安全性、保護應用程式資料,並讓使用者進一步瞭解及掌控自己的資料。如要進一步瞭解我們如何強化使用者防護措施,以及保護應用程式免於新威脅侵擾,請觀看 Google I/O 的這場演講

整合 Credential Manager 與自動填入功能

Starting with Android 15, developers can link specific views like username or password fields with Credential Manager requests, making it easier to provide a tailored user experience during the sign-in process. When the user focuses on one of these views, a corresponding request is sent to Credential Manager. The resulting credentials are aggregated across providers and displayed in autofill fallback UIs, such as inline suggestions or drop-down suggestions. The Jetpack androidx.credentials library is the preferred endpoint for developers to use and will soon be available to further enhance this feature in Android 15 and higher.

整合單鍵註冊和登入功能與生物特徵辨識提示功能

Credential Manager integrates biometric prompts into the credential creation and sign-in processes, eliminating the need for providers to manage biometric prompts. As a result, credential providers only need to focus on the results of the create and get flows, augmented with the biometric flow result. This simplified process creates a more efficient and streamlined credential creation and retrieval process.

端對端加密的金鑰管理

我們在 Android 15 中推出 E2eeContactKeysManager,這項功能可提供 OS 層級 API 來儲存加密編譯公用金鑰,方便在 Android 應用程式中進行端對端加密 (E2EE)。

E2eeContactKeysManager 旨在整合平台聯絡人應用程式,為使用者提供集中式方式,管理及驗證聯絡人的公開金鑰。

內容 URI 的權限檢查

Android 15 introduces a set of APIs that perform permission checks on content URIs:

無障礙設定

Android 15 新增了多項功能,可提升使用者無障礙體驗。

更優質的點字體驗

在 Android 15 中,我們讓 TalkBack 支援透過 USB 和安全藍牙使用 HID 標準的點字顯示器。

這個標準與滑鼠和鍵盤使用的標準類似,可協助 Android 隨著時間支援更多種類的點字顯示器。

國際化

Android 15 新增了多項功能,可提升使用者在不同語言環境下的裝置使用體驗。

中日韓變數字型

Starting with Android 15, the font file for Chinese, Japanese, and Korean (CJK) languages, NotoSansCJK, is now a variable font. Variable fonts open up possibilities for creative typography in CJK languages. Designers can explore a broader range of styles and create visually striking layouts that were previously difficult or impossible to achieve.

How the variable font for Chinese, Japanese, and Korean (CJK) languages appears with different font widths.

字元間對齊

從 Android 15 開始,系統可根據字母間距,使用字母間距 使用 JUSTIFICATION_MODE_INTER_CHARACTER。有多字的理由 Android 8.0 (API 級別 26) 首次推出的功能,以及跨字元 對於使用 空白字元做為區隔,例如中文、日文等。

使用 JUSTIFICATION_MODE_NONE 設定日文內容的版面配置。
使用 JUSTIFICATION_MODE_NONE 設定英文內容的版面配置。


使用 JUSTIFICATION_MODE_INTER_WORD 設定日文內容的版面配置。
使用 JUSTIFICATION_MODE_INTER_WORD 的英文文字版面配置。


使用 JUSTIFICATION_MODE_INTER_CHARACTER 的日文文字版面配置。
使用 JUSTIFICATION_MODE_INTER_CHARACTER 為英文內容的版面配置。

自動換行設定

Android 已開始在下列國家/地區支援日文和韓文的詞組換行符號: Android 13 (API 級別 33)。不過,雖然使用詞組的分行符號改善了 簡短的文字易讀性,對長行文字的效果不佳。 在 Android 15 中,應用程式只能針對短行套用以詞組為準的換行符號 方法是使用 LINE_BREAK_WORD_STYLE_AUTO 如果有需要 SQL 指令的分析工作負載 則 BigQuery 可能是最佳選擇這個選項可為文字選取最合適的字詞樣式選項。

以短行文字來說,使用以詞組為基準的換行符號,運作方式也相同 如 LINE_BREAK_WORD_STYLE_PHRASE,如 如下圖片:

如果是簡短的文字,LINE_BREAK_WORD_STYLE_AUTO 套用詞組換行,讓文字更清晰易讀。 這與套用 LINE_BREAK_WORD_STYLE_PHRASE

對於較長的文字,LINE_BREAK_WORD_STYLE_AUTO 會使用 no 斷行文字樣式,功能與 LINE_BREAK_WORD_STYLE_NONE,如 如下圖片:

對於長行文字,LINE_BREAK_WORD_STYLE_AUTO 套用不換行的文字樣式,讓文字更清晰易讀。 這與套用 LINE_BREAK_WORD_STYLE_NONE

額外日文變體假名字型

在 Android 15 中,旧版日语平假名(也称为 Hentaigana)字体文件 捆绑在一起半形人物的独特形状可以增加 风格或设计独特的风格 传播和理解古代日本文件的能力。

日文半角字符和文本样式 字体。

VideoLAN cone Copyright (c) 1996-2010 VideoLAN. This logo or a modified version may be used or modified by anyone to refer to the VideoLAN project or any product developed by the VideoLAN team, but does not indicate endorsement by the project.

Vulkan and the Vulkan logo are registered trademarks of the Khronos Group Inc.

OpenGL is a registered trademark and the OpenGL ES logo is a trademark of Hewlett Packard Enterprise used by permission by Khronos.