Verhaltensänderungen: Apps, die auf Android 15 oder höher ausgerichtet sind

Wie bei früheren Versionen enthält Android 15 Verhaltensänderungen, die sich auf Ihre App auswirken können. Die folgenden Verhaltensänderungen gelten ausschließlich für Apps, die auf Android 15 oder höher ausgerichtet sind. Wenn Ihre App auf Android 15 oder höher ausgerichtet ist, sollten Sie sie gegebenenfalls so anpassen, dass sie diese Verhaltensweisen richtig unterstützt.

Sehen Sie sich auch die Liste der Verhaltensänderungen an, die sich auf alle Apps auswirken, die unter Android 15 ausgeführt werden, unabhängig vom targetSdkVersion Ihrer App.

Hauptfunktion

In Android 15 werden verschiedene Kernfunktionen des Android-Systems geändert oder erweitert.

Änderungen an Vordergrunddiensten

我们将对 Android 15 中的前台服务进行以下更改。

数据同步前台服务超时行为

Android 15 introduces a new timeout behavior to dataSync for apps targeting Android 15 (API level 35) or higher. This behavior also applies to the new mediaProcessing foreground service type.

The system permits an app's dataSync services to run for a total of 6 hours in a 24-hour period, after which the system calls the running service's Service.onTimeout(int, int) method (introduced in Android 15). At this time, the service has a few seconds to call Service.stopSelf(). When Service.onTimeout() is called, the service is no longer considered a foreground service. If the service does not call Service.stopSelf(), the system throws an internal exception. The exception is logged in Logcat with the following message:

Fatal Exception: android.app.RemoteServiceException: "A foreground service of
type dataSync did not stop within its timeout: [component name]"

To avoid problems with this behavior change, you can do one or more of the following:

  1. Have your service implement the new Service.onTimeout(int, int) method. When your app receives the callback, make sure to call stopSelf() within a few seconds. (If you don't stop the app right away, the system generates a failure.)
  2. Make sure your app's dataSync services don't run for more than a total of 6 hours in any 24-hour period (unless the user interacts with the app, resetting the timer).
  3. Only start dataSync foreground services as a result of direct user interaction; since your app is in the foreground when the service starts, your service has the full six hours after the app goes to the background.
  4. Instead of using a dataSync foreground service, use an alternative API.

If your app's dataSync foreground services have run for 6 hours in the last 24, you cannot start another dataSync foreground service unless the user has brought your app to the foreground (which resets the timer). If you try to start another dataSync foreground service, the system throws ForegroundServiceStartNotAllowedException with an error message like "Time limit already exhausted for foreground service type dataSync".

Testing

To test your app's behavior, you can enable data sync timeouts even if your app is not targeting Android 15 (as long as the app is running on an Android 15 device). To enable timeouts, run the following adb command:

adb shell am compat enable FGS_INTRODUCE_TIME_LIMITS your-package-name

You can also adjust the timeout period, to make it easier to test how your app behaves when the limit is reached. To set a new timeout period, run the following adb command:

adb shell device_config put activity_manager data_sync_fgs_timeout_duration duration-in-milliseconds

新的媒体处理前台服务类型

Android 15 introduces a new foreground service type, mediaProcessing. This service type is appropriate for operations like transcoding media files. For example, a media app might download an audio file and need to convert it to a different format before playing it. You can use a mediaProcessing foreground service to make sure the conversion continues even while the app is in the background.

The system permits an app's mediaProcessing services to run for a total of 6 hours in a 24-hour period, after which the system calls the running service's Service.onTimeout(int, int) method (introduced in Android 15). At this time, the service has a few seconds to call Service.stopSelf(). If the service does not call Service.stopSelf(), the system throws an internal exception. The exception is logged in Logcat with the following message:

Fatal Exception: android.app.RemoteServiceException: "A foreground service of
type mediaProcessing did not stop within its timeout: [component name]"

To avoid having the exception, you can do one of the following:

  1. Have your service implement the new Service.onTimeout(int, int) method. When your app receives the callback, make sure to call stopSelf() within a few seconds. (If you don't stop the app right away, the system generates a failure.)
  2. Make sure your app's mediaProcessing services don't run for more than a total of 6 hours in any 24-hour period (unless the user interacts with the app, resetting the timer).
  3. Only start mediaProcessing foreground services as a result of direct user interaction; since your app is in the foreground when the service starts, your service has the full six hours after the app goes to the background.
  4. Instead of using a mediaProcessing foreground service, use an alternative API, like WorkManager.

If your app's mediaProcessing foreground services have run for 6 hours in the last 24, you cannot start another mediaProcessing foreground service unless the user has brought your app to the foreground (which resets the timer). If you try to start another mediaProcessing foreground service, the system throws ForegroundServiceStartNotAllowedException with an error message like "Time limit already exhausted for foreground service type mediaProcessing".

For more information about the mediaProcessing service type, see Changes to foreground service types for Android 15: Media processing.

Testing

To test your app's behavior, you can enable media processing timeouts even if your app is not targeting Android 15 (as long as the app is running on an Android 15 device). To enable timeouts, run the following adb command:

adb shell am compat enable FGS_INTRODUCE_TIME_LIMITS your-package-name

You can also adjust the timeout period, to make it easier to test how your app behaves when the limit is reached. To set a new timeout period, run the following adb command:

adb shell device_config put activity_manager media_processing_fgs_timeout_duration duration-in-milliseconds

对启动前台服务的 BOOT_COMPLETED 广播接收器的限制

Es gelten neue Einschränkungen für die Einführung von BOOT_COMPLETED Übertragungsempfängern Dienste im Vordergrund. BOOT_COMPLETED Empfänger dürfen nicht Folgendes starten: folgende Arten von Diensten im Vordergrund:

Wenn ein BOOT_COMPLETED-Empfänger versucht, einen dieser Dienste im Vordergrund zu starten, löst das System ForegroundServiceStartNotAllowedException aus.

Testen

Um das Verhalten Ihrer App zu testen, können Sie diese neuen Einschränkungen auch dann aktivieren, wenn Ihre Die App ist nicht auf Android 15 ausgerichtet (solange die App auf einem Android 15 ausgeführt wird) Gerät). Führen Sie den folgenden adb-Befehl aus:

adb shell am compat enable FGS_BOOT_COMPLETED_RESTRICTIONS your-package-name

Wenn Sie eine BOOT_COMPLETED-Broadcastnachricht senden möchten, ohne das Gerät neu zu starten, führen Sie den folgenden Befehl adb aus:

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED your-package-name

在应用拥有 SYSTEM_ALERT_WINDOW 权限时启动前台服务的限制

Previously, if an app held the SYSTEM_ALERT_WINDOW permission, it could launch a foreground service even if the app was currently in the background (as discussed in exemptions from background start restrictions).

If an app targets Android 15, this exemption is now narrower. The app now needs to have the SYSTEM_ALERT_WINDOW permission and also have a visible overlay window. That is, the app needs to first launch a TYPE_APPLICATION_OVERLAY window and the window needs to be visible before you start a foreground service.

If your app attempts to start a foreground service from the background without meeting these new requirements (and it does not have some other exemption), the system throws ForegroundServiceStartNotAllowedException.

If your app declares the SYSTEM_ALERT_WINDOW permission and launches foreground services from the background, it may be affected by this change. If your app gets a ForegroundServiceStartNotAllowedException, check your app's order of operations and make sure your app already has an active overlay window before it attempts to start a foreground service from the background. You can check if your overlay window is currently visible by calling View.getWindowVisibility(), or you can override View.onWindowVisibilityChanged() to get notified whenever the visibility changes.

Testing

To test your app's behavior, you can enable these new restrictions even if your app is not targeting Android 15 (as long as the app is running on an Android 15 device). To enable these new restrictions on starting foreground services from the background, run the following adb command:

adb shell am compat enable FGS_SAW_RESTRICTIONS your-package-name

Änderungen daran, wann Apps den globalen Status des „Nicht stören“-Modus ändern können

Apps that target Android 15 (API level 35) and higher can no longer change the global state or policy of Do Not Disturb (DND) on a device (either by modifying user settings, or turning off DND mode). Instead, apps must contribute an AutomaticZenRule, which the system combines into a global policy with the existing most-restrictive-policy-wins scheme. Calls to existing APIs that previously affected global state (setInterruptionFilter, setNotificationPolicy) result in the creation or update of an implicit AutomaticZenRule, which is toggled on and off depending on the call-cycle of those API calls.

Note that this change only affects observable behavior if the app is calling setInterruptionFilter(INTERRUPTION_FILTER_ALL) and expects that call to deactivate an AutomaticZenRule that was previously activated by their owners.

OpenJDK-API-Änderungen

Mit Android 15 werden die Core-Bibliotheken von Android weiter aktualisiert, um sie an die Funktionen in den neuesten OpenJDK-LTS-Releases anzupassen.

Einige dieser Änderungen können sich auf die App-Kompatibilität von Apps auswirken, die auf Android 15 (API-Level 35) ausgerichtet sind:

  • Änderungen an APIs für die Stringformatierung: Die Validierung von Argumentindex, Flags, Breite und Genauigkeit ist jetzt strenger, wenn die folgenden String.format()- und Formatter.format()-APIs verwendet werden:

    Die folgende Ausnahme wird beispielsweise ausgelöst, wenn ein Argumentindex von 0 verwendet wird (%0 im Formatstring):

    IllegalFormatArgumentIndexException: Illegal format argument index = 0
    

    In diesem Fall kann das Problem behoben werden, indem Sie den Argumentindex 1 (%1 im Formatstring) verwenden.

  • Änderungen am Komponententyp von Arrays.asList(...).toArray(): Bei Verwendung von Arrays.asList(...).toArray() ist der Komponententyp des resultierenden Arrays jetzt Object und nicht der Typ der Elemente des zugrunde liegenden Arrays. Der folgende Code löst also eine ClassCastException aus:

    String[] elements = (String[]) Arrays.asList("one", "two").toArray();
    

    In diesem Fall können Sie Collection.toArray(Object[]) verwenden, um String als Komponententyp im resultierenden Array beizubehalten:

    String[] elements = Arrays.asList("two", "one").toArray(new String[0]);
    
  • Änderungen bei der Verarbeitung von Sprachcodes: Wenn Sie die Locale API verwenden, werden Sprachcodes für Hebräisch, Jiddisch und Indonesisch nicht mehr in ihre veralteten Formen konvertiert (Hebräisch: iw, Jiddisch: ji und Indonesisch: in). Wenn Sie den Sprachcode für eines dieser Gebietsschemas angeben, verwenden Sie stattdessen die Codes aus ISO 639-1 (Hebräisch: he, Jiddisch: yi und Indonesisch: id).

  • Änderungen an zufälligen Ganzzahlfolgen: Nach den Änderungen in https://bugs.openjdk.org/browse/JDK-8301574 geben die folgenden Random.ints()-Methoden jetzt eine andere Zahlenfolge zurück als die Random.nextInt()-Methoden:

    Im Allgemeinen sollte diese Änderung nicht zu einem fehlerhaften Verhalten der App führen. Ihr Code sollte jedoch nicht davon ausgehen, dass die Sequenz, die von Random.ints()-Methoden generiert wird, mit Random.nextInt() übereinstimmt.

Die neue SequencedCollection API kann sich auf die Kompatibilität Ihrer App auswirken, nachdem Sie compileSdk in der Build-Konfiguration Ihrer App aktualisiert haben, um Android 15 (API-Level 35) zu verwenden:

  • Kollision mit den Erweiterungsfunktionen MutableList.removeFirst() und MutableList.removeLast() in kotlin-stdlib

    Der Typ List in Java wird dem Typ MutableList in Kotlin zugeordnet. Da die APIs List.removeFirst() und List.removeLast() in Android 15 (API-Level 35) eingeführt wurden, löst der Kotlin-Compiler Funktionsaufrufe wie list.removeFirst() statisch zu den neuen List-APIs auf und nicht zu den Erweiterungsfunktionen in kotlin-stdlib.

    Wenn eine App mit compileSdk auf 35 und minSdk auf 34 oder niedriger neu kompiliert und dann unter Android 14 oder niedriger ausgeführt wird, wird ein Laufzeitfehler ausgegeben:

    java.lang.NoSuchMethodError: No virtual method
    removeFirst()Ljava/lang/Object; in class Ljava/util/ArrayList;
    

    Die vorhandene Lint-Option NewApi im Android Gradle-Plug-in kann diese neuen API-Verwendungen erkennen.

    ./gradlew lint
    
    MainActivity.kt:41: Error: Call requires API level 35 (current min is 34): java.util.List#removeFirst [NewApi]
          list.removeFirst()
    

    Um die Laufzeit-Exception und die Lint-Fehler zu beheben, können die Funktionsaufrufe removeFirst() und removeLast() in Kotlin durch removeAt(0) bzw. removeAt(list.lastIndex) ersetzt werden. Wenn Sie Android Studio Ladybug | 2024.1.3 oder höher verwenden, wird auch eine Schnellkorrektur für diese Fehler angeboten.

    Entfernen Sie @SuppressLint("NewApi") und lintOptions { disable 'NewApi' }, wenn die Lint-Option deaktiviert wurde.

  • Kollision mit anderen Methoden in Java

    Den vorhandenen Typen wurden neue Methoden hinzugefügt, z. B. List und Deque. Diese neuen Methoden sind möglicherweise nicht mit den Methoden mit demselben Namen und denselben Argumenttypen in anderen Schnittstellen und Klassen kompatibel. Bei einer Kollision der Methodensignatur mit Inkompatibilität gibt der javac-Compiler einen Build-Time-Fehler aus. Beispiel:

    Beispiel für Fehler 1:

    javac MyList.java
    
    MyList.java:135: error: removeLast() in MyList cannot implement removeLast() in List
      public void removeLast() {
                  ^
      return type void is not compatible with Object
      where E is a type-variable:
        E extends Object declared in interface List
    

    Beispiel für Fehler 2:

    javac MyList.java
    
    MyList.java:7: error: types Deque<Object> and List<Object> are incompatible;
    public class MyList implements  List<Object>, Deque<Object> {
      both define reversed(), but with unrelated return types
    1 error
    

    Beispiel für Fehler 3:

    javac MyList.java
    
    MyList.java:43: error: types List<E#1> and MyInterface<E#2> are incompatible;
    public static class MyList implements List<Object>, MyInterface<Object> {
      class MyList inherits unrelated defaults for getFirst() from types List and MyInterface
      where E#1,E#2 are type-variables:
        E#1 extends Object declared in interface List
        E#2 extends Object declared in interface MyInterface
    1 error
    

    Um diese Build-Fehler zu beheben, sollte die Klasse, die diese Schnittstellen implementiert, die Methode mit einem kompatiblen Rückgabetyp überschreiben. Beispiel:

    @Override
    public Object getFirst() {
        return List.super.getFirst();
    }
    

Sicherheit

Android 15 enthält Änderungen, die die Systemsicherheit fördern, um Apps und Nutzer vor schädlichen Apps zu schützen.

Eingeschränkte TLS-Versionen

Android 15 restricts the usage of TLS versions 1.0 and 1.1. These versions had previously been deprecated in Android, but are now disallowed for apps targeting Android 15.

Sichere Starts von Hintergrundaktivitäten

Android 15 做出了一些变更,可防止恶意后台应用将其他应用置于前台、提升自身权限并滥用用户互动,从而保护用户免受恶意应用的侵害,并让用户更好地控制自己的设备。自 Android 10(API 级别 29)起,后台 activity 启动受到限制。

其他更改

  • PendingIntent 创建者更改为默认阻止后台活动启动。这有助于防止应用意外创建可能被恶意行为者滥用的 PendingIntent
  • 除非 PendingIntent 发送方允许,否则请勿将应用转至前台。此变更旨在防止恶意应用滥用在后台启动 activity 的功能。默认情况下,除非创建者允许后台 activity 启动权限或发送者具有后台 activity 启动权限,否则不允许应用将任务堆栈带到前台。
  • 控制任务堆栈的顶层 activity 如何完成其任务。如果顶部 activity 完成了一项任务,Android 将返回到上次处于活跃状态的任务。此外,如果非顶部 activity 完成其任务,Android 会返回到主屏幕;它不会阻止此非顶部 activity 完成。
  • 防止从其他应用启动任意 activity 进入您自己的任务。此变更可防止恶意应用通过创建看似来自其他应用的 activity 来对用户进行钓鱼式攻击。
  • 阻止将非可见窗口纳入后台 activity 启动的考虑范围。这有助于防止恶意应用滥用后台活动启动来向用户显示不必要或恶意的内容。

Sicherere Intents

Android 15 introduces StrictMode for intents.

In order to see detailed logs about Intent usage violations, use following method:

Kotlin

fun onCreate() {
    StrictMode.setVmPolicy(VmPolicy.Builder()
        .detectUnsafeIntentLaunch()
        .build()
    )
}

Java

public void onCreate() {
    StrictMode.setVmPolicy(new VmPolicy.Builder()
            .detectUnsafeIntentLaunch()
            .build());
}

Nutzererfahrung und System-UI

Android 15 enthält einige Änderungen, die für eine einheitlichere und intuitivere Nutzererfahrung sorgen sollen.

Änderungen am Fenstereinsatz

There are two changes related to window insets in Android 15: edge-to-edge is enforced by default, and there are also configuration changes, such as the default configuration of system bars.

全面实施政策

如果应用以 Android 15(API 级别 35)为目标平台,则在搭载 Android 15 的设备上默认以无边框显示。

以 Android 14 为目标平台且在 Android 15 设备上未以无边框显示的应用。


以 Android 15(API 级别 35)为目标平台且以无边框显示 的 Android 15 设备上的应用。此应用主要使用会自动应用边衬区的 Material 3 Compose 组件 。此屏幕不会受到 Android 15 无边框强制执行的不利影响。

这是一项重大变更,可能会对应用的界面产生不利影响。这些变更会影响以下界面区域:

  • 手势提示条导航栏
    • 默认透明。
    • 底部偏移已停用,因此除非应用了边衬区,否则内容会绘制在系统导航栏后面。
    • setNavigationBarColorR.attr#navigationBarColor 已弃用,不会影响手势导航。
    • setNavigationBarContrastEnforcedR.attr#navigationBarContrastEnforced 仍不会影响手势导航。
  • 三按钮导航
    • 默认情况下,不透明度设置为 80%,颜色可能与窗口背景颜色一致。
    • 底部偏移已停用,因此除非应用了边衬区,否则内容会绘制在系统导航栏后面。
    • setNavigationBarColorR.attr#navigationBarColor 默认设置为与窗口背景颜色一致。窗口背景必须是颜色可绘制对象,才能应用此默认设置。此 API 已弃用,但仍会影响三按钮导航。
    • setNavigationBarContrastEnforcedR.attr#navigationBarContrastEnforced 默认值为 true,这会在三按钮导航中添加 80% 不透明的背景。
  • 状态栏
    • 默认透明。
    • 顶部偏移已停用,因此除非应用了边衬区,否则内容会绘制在状态栏后面。
    • setStatusBarColorR.attr#statusBarColor 已弃用,不会影响 Android 15。
    • setStatusBarContrastEnforcedR.attr#statusBarContrastEnforced 已弃用,但仍会影响 Android 15。
  • 刘海屏
    • 非浮动窗口的 layoutInDisplayCutoutMode 必须为 LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYSSHORT_EDGESNEVERDEFAULT 会被解读为 ALWAYS,这样用户就不会看到因显示屏刘海屏而产生的黑条,并且会以无边框显示。

以下示例展示了应用在以 Android 15(API 级别 35)为目标平台之前和之后,以及在应用边衬区之前和之后的效果。此示例并不全面,在 Android Auto 上可能会显示不同的效果。

以 Android 14 为目标平台且在 Android 15 设备上未以无边框显示的应用。
以 Android 15(API 级别 35)为目标平台且在 Android 15 设备上以无边框显示的应用。不过,由于 Android 15 无边框强制执行,许多元素现在会被状态栏、三按钮导航栏或刘海屏遮盖。被遮盖的界面包括 Material 2 顶部应用栏、悬浮操作按钮和列表项。
以 Android 15(API 级别 35)为目标平台且在 Android 15 设备上以无边框显示的应用,并应用了边衬区,因此界面不会被 遮盖。
如果您的应用已以无边框显示,需要检查哪些内容

如果您的应用已以 无边框 显示并应用了边衬区,则大部分情况下 不会受到影响,但在以下情形中除外。不过,即使您认为自己不会受到影响,我们也建议您测试应用。

  • 您有一个非浮动窗口,例如使用 SHORT_EDGESNEVERDEFAULT 而不是 LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYSActivity。如果您的应用在启动时崩溃,可能是因为启动画面所致。您可以将 核心 启动画面 依赖项升级到 1.2.0-alpha01 或更高版本,也可以设置 window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutInDisplayCutoutMode.always
  • 可能存在流量较低的屏幕,其界面被遮盖。验证这些访问量较少的屏幕是否没有被遮盖的界面。流量较低的屏幕包括:
    • 新手入门或登录屏幕
    • “设置”页面
如果您的应用尚未以无边框显示,需要检查哪些内容

如果您的应用尚未以无边框显示,则很可能会受到影响。除了已以无边框显示的应用的情形之外,您还应考虑以下情况:

  • 如果您的应用在 Compose 中使用了 Material 3 组件 ( androidx.compose.material3),例如 TopAppBarBottomAppBarNavigationBar,这些组件可能不会 受到影响,因为它们会自动处理边衬区。
  • 如果应用使用的是 Compose 中的 Material 2 组件 ( androidx.compose.material),这些组件 本身并不会自动处理边衬区。不过,您可以获得边衬区的访问权限,然后手动应用边衬区。在 androidx.compose.material 1.6.0 及更高版本中,使用 windowInsets 参数可为 BottomAppBarTopAppBarBottomNavigationNavigationRail 手动应用边衬区。 同样,对于 Scaffold,请使用 contentWindowInsets 参数。
  • 如果应用使用了视图和 Material 组件 (com.google.android.material),则大多数基于视图的 Material 组件(例如 BottomNavigationViewBottomAppBarNavigationRailViewNavigationView)都会处理边衬区,因此不需要执行额外的操作。不过,您需要添加 android:fitsSystemWindows="true" ,如果使用 AppBarLayout
  • 对于自定义可组合项,请手动应用边衬区作为内边距。如果您的 内容位于 Scaffold 中,则可以使用 Scaffold 内边距值来使用边衬区。否则,请使用其中一个 WindowInsets应用内边距。
  • 如果应用使用的是视图和 BottomSheetSideSheet 或自定义 容器,请使用 ViewCompat.setOnApplyWindowInsetsListener应用内边距。对于 RecyclerView,请使用此监听器应用内边距,同时添加 clipToPadding="false"
如果您的应用必须提供自定义背景保护,需要检查哪些内容

如果您的应用必须为“三按钮”导航或 状态栏提供自定义背景保护,则应用应使用 WindowInsets.Type#tappableElement() 将可组合函数或视图放置在系统栏后面 ,以获取“三按钮” 导航栏高度或 WindowInsets.Type#statusBars

其他无边框资源

如需了解有关应用边衬区的其他注意事项,请参阅无边框视图无边框 Compose 指南。

已弃用的 API

以下 API 已弃用,但未停用:

以下 API 已弃用并已停用:

稳定配置

If your app targets Android 15 (API level 35) or higher, Configuration no longer excludes the system bars. If you use the screen size in the Configuration class for layout calculation, you should replace it with better alternatives like an appropriate ViewGroup, WindowInsets, or WindowMetricsCalculator depending on your need.

Configuration has been available since API 1. It is typically obtained from Activity.onConfigurationChanged. It provides information like window density, orientation, and sizes. One important characteristic about the window sizes returned from Configuration is that it previously excluded the system bars.

The configuration size is typically used for resource selection, such as /res/layout-h500dp, and this is still a valid use case. However, using it for layout calculation has always been discouraged. If you do so, you should move away from it now. You should replace the use of Configuration with something more suitable depending on your use case.

If you use it to calculate the layout, use an appropriate ViewGroup, such as CoordinatorLayout or ConstraintLayout. If you use it to determine the height of the system navbar, use WindowInsets. If you want to know the current size of your app window, use computeCurrentWindowMetrics.

The following list describes the fields affected by this change:

Das Attribut „elegantTextHeight“ ist standardmäßig auf „true“ gesetzt.

For apps targeting Android 15 (API level 35), the elegantTextHeight TextView attribute becomes true by default, replacing the compact font used by default with some scripts that have large vertical metrics with one that is much more readable. The compact font was introduced to prevent breaking layouts; Android 13 (API level 33) prevents many of these breakages by allowing the text layout to stretch the vertical height utilizing the fallbackLineSpacing attribute.

In Android 15, the compact font still remains in the system, so your app can set elegantTextHeight to false to get the same behavior as before, but it is unlikely to be supported in upcoming releases. So, if your app supports the following scripts: Arabic, Lao, Myanmar, Tamil, Gujarati, Kannada, Malayalam, Odia, Telugu or Thai, test your app by setting elegantTextHeight to true.

elegantTextHeight behavior for apps targeting Android 14 (API level 34) and lower.
elegantTextHeight behavior for apps targeting Android 15.

TextView-Breite ändert sich bei komplexen Buchstabenformen

In previous versions of Android, some cursive fonts or languages that have complex shaping might draw the letters in the previous or next character's area. In some cases, such letters were clipped at the beginning or ending position. Starting in Android 15, a TextView allocates width for drawing enough space for such letters and allows apps to request extra paddings to the left to prevent clipping.

Because this change affects how a TextView decides the width, TextView allocates more width by default if the app targets Android 15 (API level 35) or higher. You can enable or disable this behavior by calling the setUseBoundsForWidth API on TextView.

Because adding left padding might cause a misalignment for existing layouts, the padding is not added by default even for apps that target Android 15 or higher. However, you can add extra padding to preventing clipping by calling setShiftDrawingOffsetForStartOverhang.

The following examples show how these changes can improve text layout for some fonts and languages.

Standard layout for English text in a cursive font. Some of the letters are clipped. Here is the corresponding XML:

<TextView
    android:fontFamily="cursive"
    android:text="java" />
Layout for the same English text with additional width and padding. Here is the corresponding XML:

<TextView
    android:fontFamily="cursive"
    android:text="java"
    android:useBoundsForWidth="true"
    android:shiftDrawingOffsetForStartOverhang="true" />
Standard layout for Thai text. Some of the letters are clipped. Here is the corresponding XML:

<TextView
    android:text="คอมพิวเตอร์" />
Layout for the same Thai text with additional width and padding. Here is the corresponding XML:

<TextView
    android:text="คอมพิวเตอร์"
    android:useBoundsForWidth="true"
    android:shiftDrawingOffsetForStartOverhang="true" />

Gebietsschemaabhängige Standardzeilenhöhe für EditText

In previous versions of Android, the text layout stretched the height of the text to meet the line height of the font that matched the current locale. For example, if the content was in Japanese, because the line height of the Japanese font is slightly larger than the one of a Latin font, the height of the text became slightly larger. However, despite these differences in line heights, the EditText element was sized uniformly, regardless of the locale being used, as illustrated in the following image:

Three boxes representing EditText elements that can contain text from English (en), Japanese (ja), and Burmese (my). The height of the EditText is the same, even though these languages have different line heights from each other.

For apps targeting Android 15 (API level 35), a minimum line height is now reserved for EditText to match the reference font for the specified Locale, as shown in the following image:

Three boxes representing EditText elements that can contain text from English (en), Japanese (ja), and Burmese (my). The height of the EditText now includes space to accommodate the default line height for these languages' fonts.

If needed, your app can restore the previous behavior by specifying the useLocalePreferredLineHeightForMinimum attribute to false, and your app can set custom minimum vertical metrics using the setMinimumFontMetrics API in Kotlin and Java.

Kamera und Medien

Unter Android 15 werden die folgenden Änderungen am Kamera- und Medienverhalten für Apps eingeführt, die auf Android 15 oder höher ausgerichtet sind.

Einschränkungen beim Anfordern des Audiofokus

Apps, die auf Android 15 (API-Level 35) ausgerichtet sind, müssen die oberste App sein oder einen Dienst im Vordergrund ausführen, um den Audiofokus anfordern zu können. Wenn eine App versucht, den Fokus anzufordern, ohne eine dieser Anforderungen zu erfüllen, gibt der Aufruf AUDIOFOCUS_REQUEST_FAILED zurück.

Weitere Informationen zum Audiofokus finden Sie unter Audiofokus verwalten.

Aktualisierte Einschränkungen für Nicht-SDKs

Android 15 enthält aktualisierte Listen eingeschränkter Nicht-SDK-Schnittstellen, die auf der Zusammenarbeit mit Android-Entwicklern und den neuesten internen Tests basieren. Wir sorgen nach Möglichkeit dafür, dass öffentliche Alternativen verfügbar sind, bevor wir Nicht-SDK-Schnittstellen einschränken.

Wenn Ihre App nicht auf Android 15 ausgerichtet ist, wirken sich einige dieser Änderungen möglicherweise nicht sofort auf Sie aus. Zwar kann Ihre App abhängig vom Ziel-API-Level Ihrer App auf einige Nicht-SDK-Schnittstellen zugreifen, die Verwendung einer Nicht-SDK-Methode oder eines Nicht-SDK-Felds birgt jedoch immer ein hohes Risiko, dass Ihre App nicht mehr funktioniert.

Wenn Sie sich nicht sicher sind, ob Ihre App Nicht-SDK-Schnittstellen verwendet, können Sie Ihre App testen, um das herauszufinden. Wenn Ihre App auf Nicht-SDK-Schnittstellen basiert, sollten Sie mit der Planung einer Migration zu SDK-Alternativen beginnen. Wir wissen jedoch, dass es für einige Apps gültige Anwendungsfälle für die Verwendung von Nicht-SDK-Schnittstellen gibt. Wenn Sie für eine Funktion in Ihrer App keine Alternative zur Verwendung einer Nicht-SDK-Schnittstelle finden, sollten Sie eine neue öffentliche API anfordern.

Weitere Informationen zu den Änderungen in dieser Android-Version finden Sie unter Änderungen an den Einschränkungen für nicht SDK-spezifische Oberflächen in Android 15. Weitere Informationen zu Nicht-SDK-Schnittstellen finden Sie unter Einschränkungen für Nicht-SDK-Schnittstellen.