[null,null,["最后更新时间 (UTC):2025-08-21。"],[],[],null,["# Deprecations\n\nWith each release, specific Android APIs may become obsolete or need to be\nrefactored to provide a better developer experience or support new platform\ncapabilities. In these cases, Android will officially deprecate the obsolete\nAPIs and direct developers to new APIs to use instead.\n\nDeprecation means that we've ended official support for the APIs, but they will\ncontinue to remain available to developers. This page highlights some of the\ndeprecations in this release of Android. To see other deprecations, refer to the\n[API diff report](/sdk/api_diff/31/changes).\n\nRenderScript\n------------\n\nStarting with Android 12, the RenderScript APIs are deprecated. They will\ncontinue to function, but we expect that device and component manufacturers will\nstop providing hardware acceleration support over time. To take full advantage\nof GPU acceleration, we recommend [migrating away from RenderScript](/guide/topics/renderscript/migrate).\n\nAndroid playlists\n-----------------\n\nAndroid [playlists](/reference/android/provider/MediaStore.Audio.Playlists) are\ndeprecated. The API is no longer maintained but the current functionality\nremains for compatibility.\n\nWe recommend reading and saving playlists as [m3u](https://en.wikipedia.org/wiki/M3U)\nfiles.\n\nDisplay API deprecations\n------------------------\n\nAndroid devices are becoming available in many different form factors, such as\nlarge screens, tablets, and foldables. In order to render content appropriately\nfor each device, your app needs to determine the screen or display size. Over\ntime Android provided different APIs for retrieving this information. In\nAndroid 11 we introduced the\n[`WindowMetrics`](/reference/android/view/WindowMetrics) API and deprecated\nthese methods:\n\n- [`Display.getSize()`](/reference/android/view/Display#getSize(android.graphics.Point))\n- [`Display.getMetrics()`](/reference/android/view/Display#getMetrics(android.util.DisplayMetrics))\n\nIn Android 12 we continue to recommend using `WindowMetrics`\nand are deprecating these methods:\n\n- [`Display.getRealSize()`](/reference/android/view/Display#getRealSize(android.graphics.Point))\n- [`Display.getRealMetrics()`](/reference/android/view/Display#getRealMetrics(android.util.DisplayMetrics))\n\nApps should use the `WindowMetrics` APIs to query the bounds of their window, or\n[`Configuration.densityDpi`](/reference/android/content/res/Configuration#densityDpi)\nto query the current density.\n\nNote that the Jetpack [`WindowManager`](/jetpack/androidx/releases/window)\nlibrary includes a [`WindowMetrics`](/reference/androidx/window/layout/WindowMetrics)\nclass that supports Android 4.0.1 (API level 14) and higher.\n\n#### Examples\n\nHere are some examples how to use `WindowMetrics`.\n\nFirst, be sure your app can make its activities\n[fully resizable](https://developer.android.com/guide/topics/ui/multi-window).\n\nAn activity should rely upon `WindowMetrics` from an activity context for\nany UI-related work, particularly\n[`WindowManager.getCurrentWindowMetrics()`](/reference/android/view/WindowManager#getCurrentWindowMetrics()).\n\nIf your app creates a `MediaProjection`, the bounds must be correctly sized\nsince the projection captures the display. If the app is fully resizable, the\nactivity context returns the correct bounds. \n\n### Kotlin\n\n```kotlin\nval projectionMetrics = activityContext\n .getSystemService(WindowManager::class.java).maximumWindowMetrics\n```\n\n### Java\n\n```java\nWindowMetrics projectionMetrics = activityContext\n .getSystemService(WindowManager.class).getMaximumWindowMetrics();\n```\n\nIf the app is not fully resizable, it must query the bounds from a\n`WindowContext` instance, and retrieve the WindowMetrics of the maximum display\narea available to the application using\n[`WindowManager.getMaximumWindowMetrics()`](/reference/android/view/WindowManager#getMaximumWindowMetrics()) \n\n### Kotlin\n\n```kotlin\nval windowContext = context.createWindowContext(mContext.display!!,\n WindowManager.LayoutParams.TYPE_APPLICATION, null)\nval projectionMetrics = windowContext.getSystemService(WindowManager::class.java)\n .maximumWindowMetrics\n```\n\n### Java\n\n```java\nContext windowContext = mContext.createWindowContext(mContext.getDisplay(),\n WindowManager.LayoutParams.TYPE_APPLICATION, null;\nWindowMetrics projectionMetrics = windowContext.getWindowManager()\n .getMaximumWindowMetrics();\n```\n| **Note:** Any library that uses `MediaProjection` should follow this advice as well and query the appropriate `WindowMetrics` for the app window."]]