نظرة عامة على الميزات وواجهات برمجة التطبيقات

يقدّم نظام التشغيل Android 14 ميزات وواجهات برمجة تطبيقات رائعة للمطوّرين. تساعدك المعلومات التالية في معرفة ميزات تطبيقاتك والبدء باستخدام واجهات برمجة التطبيقات ذات الصلة.

للحصول على قائمة مفصّلة بواجهات برمجة التطبيقات التي تمت إضافتها وتعديلها وإزالتها، اقرأ الفرق بين واجهة برمجة التطبيقات. بشكل تقريري. للاطّلاع على تفاصيل عن واجهات برمجة التطبيقات المُضافة، يُرجى الانتقال إلى مرجع واجهات برمجة تطبيقات Android. بالنسبة إلى الإصدار 14 من نظام التشغيل Android، ابحث عن واجهات برمجة التطبيقات التي تمت إضافتها في المستوى 34 لواجهة برمجة التطبيقات. للتعرّف على المجالات التي قد تؤثر فيها تغييرات النظام الأساسي في تطبيقاتك، احرص على الاطّلاع على تغييرات السلوك في الإصدار 14 من Android للتطبيقات التي تستهدف الإصدار 14 ولجميع التطبيقات.

التوافق مع أسواق عالمية

إعدادات اللغة المخصّصة حسب التطبيقات

Android 14 expands on the per-app language features that were introduced in Android 13 (API level 33) with these additional capabilities:

  • Automatically generate an app's localeConfig: Starting with Android Studio Giraffe Canary 7 and AGP 8.1.0-alpha07, you can configure your app to support per-app language preferences automatically. Based on your project resources, the Android Gradle plugin generates the LocaleConfig file and adds a reference to it in the final manifest file, so you no longer have to create or update the file manually. AGP uses the resources in the res folders of your app modules and any library module dependencies to determine the locales to include in the LocaleConfig file.

  • Dynamic updates for an app's localeConfig: Use the setOverrideLocaleConfig() and getOverrideLocaleConfig() methods in LocaleManager to dynamically update your app's list of supported languages in the device's system settings. Use this flexibility to customize the list of supported languages per region, run A/B experiments, or provide an updated list of locales if your app utilizes server-side pushes for localization.

  • App language visibility for input method editors (IMEs): IMEs can utilize the getApplicationLocales() method to check the language of the current app and match the IME language to that language.

واجهة برمجة تطبيقات التدفّق النحوي

يتحدّث 3 مليارات شخص لغات جنسانية: وهي لغات تتغيّر فيها فئاتها النحوية، مثل الأسماء والأفعال والصفات وحروف الجر، وفقًا للجنس الذي يحدّده الشخص أو الشيء الذي تتحدث عنه. في العادة، تستخدم العديد من اللغات التي تراعي الجنس النوع النحوي الذكوري كجنس تلقائي أو عام.

يمكن أن يؤدي استخدام الجنس النحوي غير الصحيح للمستخدمين، مثل مخاطبة النساء باستخدام الجنس النحوي للذكور، إلى التأثير سلبًا في أدائهم وسلوكهم. في المقابل، يمكن أن يؤدي استخدام واجهة مستخدم تتضمّن لغة تمثل بشكلٍ صحيح الجنس النحوي للمستخدم إلى تحسين تفاعله مع التطبيق وتوفير تجربة أكثر تخصيصًا وطبيعية.

To help you build a user-centric UI for gendered languages, Android 14 introduces the Grammatical Inflection API, which lets you add support for grammatical gender without refactoring your app.

الإعدادات المفضّلة للمنطقة

Regional preferences enable users to personalize temperature units, the first day of the week, and numbering systems. A European living in the United States might prefer temperature units to be in Celsius rather than Fahrenheit and for apps to treat Monday as the beginning of the week instead of the US default of Sunday.

New Android Settings menus for these preferences provide users with a discoverable and centralized location to change app preferences. These preferences also persist through backup and restore. Several APIs and intents—such as getTemperatureUnit and getFirstDayOfWeek— grant your app read access to user preferences, so your app can adjust how it displays information. You can also register a BroadcastReceiver on ACTION_LOCALE_CHANGED to handle locale configuration changes when regional preferences change.

To find these settings, open the Settings app and navigate to System > Languages & input > Regional preferences.

Regional preferences screen in Android system settings.
Temperature options for regional preferences in Android system settings.

تسهيل الاستخدام

تكبير الخط غير الخطي إلى 200%

从 Android 14 开始,系统支持字体放大高达 200%,为弱视用户提供了符合网络内容无障碍指南 (WCAG) 的其他无障碍选项。

为防止屏幕上的大文本元素放大过大,系统会采用非线性放大曲线。这种放大策略意味着大号文本的放大比例不会与较小的文本相同。非线性字体缩放有助于保持不同大小元素之间的比例层次结构,同时缓解高级别线性文本缩放的问题(例如文本被截断或文本因超大显示大小而难以阅读)。

使用非线性字体放大测试应用

在设备的无障碍设置中启用最大字号,以测试应用。

如果您已经使用放大像素 (sp) 单位来定义文本大小,那么这些额外的选项和缩放改进会自动应用于应用中的文本。但是,您仍然应该在启用最大字体大小 (200%) 的情况下执行界面测试,以确保应用正确应用字体大小,并且可以适应更大的字体大小,而不影响易用性。

要启用 200% 字号,请按以下步骤操作:

  1. 打开“设置”应用,然后依次前往无障碍 > 显示大小和文字
  2. 字号选项中,点按加号 (+) 图标,直到启用最大字号设置,如本部分随附的图片所示。

针对文本大小使用放大像素 (sp) 单位

请务必始终以 sp 为单位指定文本大小。当应用使用 sp 单位时,Android 可以应用用户的首选文本大小并相应地缩放。

不要为内边距使用 sp 单位,也不假设隐式内边距定义视图高度:使用非线性字体缩放 sp 尺寸可能不成比例,因此 4sp + 20sp 可能不等于 24sp。

转换放大像素 (sp) 单位

使用 TypedValue.applyDimension() 从 sp 单位转换为像素,并使用 TypedValue.deriveDimension() 将像素转换为 sp。这些方法会自动应用适当的非线性缩放曲线。

避免使用 Configuration.fontScaleDisplayMetrics.scaledDensity 对方程进行硬编码。由于字体缩放是非线性的,因此 scaledDensity 字段不再准确。fontScale 字段应仅用于提供信息,因为字体不再使用单个标量值进行缩放。

对 lineHeight 使用 sp 单位

始终使用 sp 单位(而非 dp)定义 android:lineHeight,以便行高随文本一起缩放。否则,如果您的文本为 sp,而 lineHeight 以 dp 或 px 为单位,则文本无法缩放且看起来狭窄。TextView 会自动更正 lineHeight 以保留您预期的比例,但前提是以 sp 为单位同时定义 textSizelineHeight

الكاميرا والوسائط

دقة HDR الفائقة للصور

标准动态范围 (SDR) 与高动态范围 (HDR) 图片质量对比示意图。

Android 14 新增了对高动态范围 (HDR) 图片的支持,可在拍摄照片时保留更多来自传感器的信息,从而实现鲜艳的色彩和更高的对比度。Android 使用 Ultra HDR 格式,该格式与 JPEG 图片完全向后兼容,可让应用与 HDR 图片无缝互操作,并根据需要以标准动态范围 (SDR) 显示这些图片。

当您的应用选择为其 activity 窗口使用 HDR 界面(通过清单条目或通过在运行时调用 Window.setColorMode())时,框架会自动在界面中以 HDR 格式渲染这些图片。您还可以在受支持的设备上拍摄压缩的 Ultra HDR 静态图片。从传感器中恢复的颜色越多,后期编辑的灵活性就越高。与 Ultra HDR 图片关联的 Gainmap 可用于使用 OpenGL 或 Vulkan 渲染这些图片。

ميزات التكبير والتركيز والعرض اللاحق والمزيد في إضافات الكاميرا

Android 14 upgrades and improves camera extensions, allowing apps to handle longer processing times, which enables improved images using compute-intensive algorithms like low-light photography on supported devices. These features give users an even more robust experience when using camera extension capabilities. Examples of these improvements include:

تكبير/تصغير ضمن المستشعر

CameraCharacteristics 中的 REQUEST_AVAILABLE_CAPABILITIES_STREAM_USE_CASE 包含 SCALER_AVAILABLE_STREAM_USE_CASES_CROPPED_RAW 时,您的应用可以使用高级传感器功能,将剪裁后的 RAW 数据流的像素与全视野范围相同,方法是将 CaptureRequest 与将数据流用例设置为 CameraMetadata.SCALER_AVAILABLE_STREAM_USE_CASES_CROPPED_RAW 的 RAW 目标搭配使用。通过实现请求替换控件,更新后的相机可让用户在其他相机控件准备就绪之前使用缩放控件。

صوت USB بدون فقدان الجودة

يتيح نظام Android 14 استخدام تنسيقات الصوت غير القابل للفقد لتوفير تجارب رائعة تتعلّق بالصوت عبر سماعات الرأس السلكية USB. يمكنك الاستعلام عن جهاز USB للحصول على سمات أداة المزج المفضّلة، وتسجيل مستمع للتغييرات فيسمات أداة المزج المفضّلة، وضبط سمات أداة المزج باستخدام فئة AudioMixerAttributes. تمثّل هذه الفئة التنسيق، مثل قناع القناة ومعدّل أخذ العينات وسلوك أداة مزج الصوت. تسمح الفئة بإرسال الصوت مباشرةً، بدون مزج أو تعديل مستوى الصوت أو تطبيق تأثيرات المعالجة.

أدوات وإنتاجية المطوّرين

مدير بيانات الاعتماد

Android 14 将 Credential Manager 添加为平台 API,并通过使用 Google Play 服务的 Jetpack 库,向后额外支持 Android 4.4(API 级别 19)设备。Credential Manager 旨在通过 API 使用用户配置的凭据提供程序检索和存储凭据,让用户更轻松地登录。Credential Manager 在单个 API 中支持多种登录方法,包括用户名和密码、通行密钥和联合登录解决方案(如“使用 Google 账号登录”)。

通行密钥具有许多优势。例如,通行密钥是基于业界标准构建的,可在各种不同的操作系统和浏览器生态系统中使用,并且可用于网站和应用。

如需了解详情,请参阅 Credential Manager 和通行密钥文档以及介绍 Credential Manager 和通行密钥的博文

Health Connect

Health Connect is an on-device repository for user health and fitness data. It allows users to share data between their favorite apps, with a single place to control what data they want to share with these apps.

On devices running Android versions prior to Android 14, Health Connect is available to download as an app on the Google Play store. Starting with Android 14, Health Connect is part of the platform and receives updates through Google Play system updates without requiring a separate download. With this, Health Connect can be updated frequently, and your apps can rely on Health Connect being available on devices running Android 14 or higher. Users can access Health Connect from the Settings in their device, with privacy controls integrated into the system settings.

Users can get started using Health Connect without a separate app download on devices running Android 14 or higher.
Users can control which apps have access to their health and fitness data through system settings.

Health Connect includes several new features in Android 14, such as exercise routes, allowing users to share a route of their workout which can be visualized on a map. A route is defined as a list of locations saved within a window of time, and your app can insert routes into exercise sessions, tying them together. To ensure that users have complete control over this sensitive data, users must allow sharing individual routes with other apps.

For more information, see the Health Connection documentation and the blogpost on What's new in Android Health.

تحديثات OpenJDK 17

Android 14 continues the work of refreshing Android's core libraries to align with the features in the latest OpenJDK LTS releases, including both library updates and Java 17 language support for app and platform developers.

The following features and improvements are included:

  • Updated approximately 300 java.base classes to Java 17 support.
  • Text Blocks, which introduce multi-line string literals to the Java programming language.
  • Pattern Matching for instanceof, which allows an object to be treated as having a specific type in an instanceof without any additional variables.
  • Sealed classes, which allow you restrict which classes and interfaces can extend or implement them.

Thanks to Google Play system updates (Project Mainline), over 600 million devices are enabled to receive the latest Android Runtime (ART) updates that include these changes. This is part of our commitment to give apps a more consistent, secure environment across devices, and to deliver new features and capabilities to users independent of platform releases.

Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

تحسينات لمتاجر التطبيقات

Android 14 引入了多个 PackageInstaller API,可帮助应用商店改善其用户体验。

下载之前请求批准安装

安装或更新应用可能需要用户批准。例如,当使用 REQUEST_INSTALL_PACKAGES 权限的安装程序尝试安装新应用时。在之前的 Android 版本中,只有在将 APK 写入安装会话并且提交会话后,应用商店才能请求用户批准。

从 Android 14 开始,requestUserPreapproval() 方法可让安装程序在提交安装会话之前请求用户批准。此项改进可让应用商店将任何 APK 的下载操作推迟到用户批准安装之后。此外,用户批准安装后,应用商店可以在后台下载并安装应用,而不会干扰用户。

承担未来更新的责任

借助 setRequestUpdateOwnership() 方法,安装程序可以向系统表明它打算负责将被安装的应用未来的更新。此 capability 可实现更新所有权强制执行,即仅允许更新所有者为应用安装自动更新。更新所有权强制执行有助于确保用户仅收到来自预期应用商店的更新。

任何其他安装程序(包括使用 INSTALL_PACKAGES 权限的安装程序)都必须获得用户的明确批准,才能安装更新。如果用户决定继续从其他来源安装更新,则会失去更新所有权。

在干扰较少的时段更新应用

应用商店通常希望避免更新正在使用的应用,因为这会导致应用正在运行的进程被终止,而这可能会中断用户正在执行的操作。

从 Android 14 开始,InstallConstraints API 让安装程序可以确保其应用更新在适当的时机进行。例如,应用商店可以调用 commitSessionAfterInstallConstraintsAreMet() 方法来确保仅在用户不再与相应应用互动时才进行更新。

无缝安装可选拆分

借助拆分 APK,应用的功能可以通过单独的 APK 文件提供,而不是以单体式 APK 的形式提供。借助拆分 APK,应用商店可以优化不同应用组件的提供。例如,应用商店可能会根据目标设备的属性进行优化。自在 API 级别 22 中引入以来,PackageInstaller API 一直支持拆分。

在 Android 14 中,setDontKillApp() 方法可让安装程序指明在安装新的拆分项时应用的运行进程不应终止。应用商店可以使用此功能,在用户使用应用时无缝安装应用的新功能。

حِزم البيانات الوصفية للتطبيق

Starting in Android 14, the Android package installer lets you specify app metadata, such as data safety practices, to include on app store pages such as Google Play.

رصد الحالات التي يلتقط فيها المستخدمون لقطات شاشة للجهاز

To create a more standardized experience for detecting screenshots, Android 14 introduces a privacy-preserving screenshot detection API. This API lets apps register callbacks on a per-activity basis. These callbacks are invoked, and the user is notified, when the user takes a screenshot while that activity is visible.

تجربة المستخدم

إجراءات مخصّصة في "قائمة مشاركة البيانات" وترتيب محسَّن

Android 14 更新了系统 Sharesheet,以便为用户提供自定义应用操作和信息更丰富的预览结果。

添加自定义操作

对于 Android 14,您的应用可以向其调用的系统 Sharesheet 添加自定义操作

分享表格中自定义操作的屏幕截图。

提高直接共享目标的排名

Android 14 根据来自应用的更多信号来确定直接共享目标的排名,以便为用户提供更实用的结果。为了提供最实用的排名信号,请遵循提高直接共享目标排名的准则。通讯应用还可以报告出站和入站消息的快捷方式使用情况

共享表单中的“直接分享”行,如 1
所示

دعم الصور المتحركة المدمَجة والمخصَّصة لإظهار ميزة "الظهور التلقائي"

فيديو: الصور المتحركة لميزة "الترجيع التوقّعي"

قدّم نظام التشغيل Android 13 إيماءة الرجوع إلى الشاشة الرئيسية التنبؤية من خلال خيار مخصّص للمطوّرين. عند استخدامها في تطبيق متوافق مع تفعيل خيار المطوّر، يؤدي التمرير سريعًا للخلف إلى عرض صورة متحركة تشير إلى أنّ إيماءة الرجوع تؤدي إلى الخروج من التطبيق والرجوع إلى الشاشة الرئيسية.

يتضمّن Android 14 تحسينات متعدّدة وإرشادات جديدة بشأن ميزة "الرجوع التوقّعي":

في إصدار معاينة Android 14 هذا، تظل جميع ميزات "الترجيع التوقّعي" متاحة فقط من خلال خيار المطوّر. اطّلِع على دليل المطوّر لنقل بيانات تطبيقك إلى ميزة "الرجوع التوقّعي"، بالإضافة إلى دليل المطوّر لإنشاء التحولات المخصّصة داخل التطبيق.

عمليات إلغاء الإعدادات التي تحدّدها الشركة المصنّعة للأجهزة ذات الشاشات الكبيرة لكل تطبيق

تتيح عمليات إلغاء الإعدادات على مستوى التطبيق لصنّاع الأجهزة تغيير سلوك التطبيقات على الأجهزة ذات الشاشات الكبيرة. على سبيل المثال، عند إلغاء FORCE_RESIZE_APP، يتم توجيه النظام لتغيير حجم التطبيق ليلائم أبعاد العرض (وتجنُّب وضع توافق الحجم) حتى في حال ضبط resizeableActivity="false" في بيان التطبيق.

تهدف عمليات الإلغاء إلى تحسين تجربة المستخدم على الشاشات الكبيرة.

تتيح لك سمات البيان الجديدة إيقاف بعض عمليات إلغاء الشركة المصنّعة للجهاز لتطبيقك.

إعدادات المستخدم على الشاشة الكبيرة لكل تطبيق

Per-app overrides change the behavior of apps on large screen devices. For example, the OVERRIDE_MIN_ASPECT_RATIO_LARGE device manufacturer override sets the app aspect ratio to 16:9 regardless of the app's configuration.

Android 14 QPR1 enables users to apply per‑app overrides by means of a new settings menu on large screen devices.

مشاركة شاشة التطبيق

App screen sharing enables users to share an app window instead of the entire device screen during screen content recording.

With app screen sharing, the status bar, navigation bar, notifications, and other system UI elements are excluded from the shared display. Only the content of the selected app is shared.

App screen sharing improves productivity and privacy by enabling users to run multiple apps but limit content sharing to a single app.

ميزة "الرد السريع" المستندة إلى نموذج اللغة الكبير في Gboard على هاتف Pixel 8 Pro

على أجهزة Pixel 8 Pro التي تم تثبيت حزمة ميزات شهر كانون الأول (ديسمبر) عليها، يمكن للمطوّرين تجربة ردود سريعة بجودة أعلى في Gboard، وذلك باستخدام نماذج لغوية كبيرة (LLM) على الجهاز تعمل على معالج Google Tensor.

تتوفّر هذه الميزة في إصدار تجريبي محدود باللغة الإنجليزية (الولايات المتحدة) في WhatsApp وLine وKakaoTalk. تتطلّب الميزة استخدام جهاز Pixel 8 Pro مع Gboard ك keyboard.

لتجربة هذه الميزة، عليك أولاً تفعيلها من خلال الانتقال إلى الإعدادات > خيارات المطوّرين > إعدادات AICore > تفعيل ميزة Aicore Persistent.

بعد ذلك، افتح محادثة في تطبيق متوافق للاطّلاع على ميزة "الرد السريع" المستندة إلى نموذج اللغة الكبيرة في شريط اقتراحات Gboard استجابةً للرسائل الواردة.

تستخدم Gboard نماذج لغوية كبيرة على الجهاز لتقديم ردود سريعة ذكية وعالية الجودة.

الرسومات

يمكن البحث في المسارات وإنشاء خطوط بينية لها.

Android's Path API is a powerful and flexible mechanism for creating and rendering vector graphics, with the ability to stroke or fill a path, construct a path from line segments or quadratic or cubic curves, perform boolean operations to get even more complex shapes, or all of these simultaneously. One limitation is the ability to find out what is actually in a Path object; the internals of the object are opaque to callers after creation.

To create a Path, you call methods such as moveTo(), lineTo(), and cubicTo() to add path segments. But there has been no way to ask that path what the segments are, so you must retain that information at creation time.

Starting in Android 14, you can query paths to find out what's inside of them. First, you need to get a PathIterator object using the Path.getPathIterator API:

KotlinJava
val path = Path().apply {
    moveTo(1.0f, 1.0f)
    lineTo(2.0f, 2.0f)
    close()
}
val pathIterator = path.pathIterator
Path path = new Path();
path.moveTo(1.0F, 1.0F);
path.lineTo(2.0F, 2.0F);
path.close();
PathIterator pathIterator = path.getPathIterator();

Next, you can call PathIterator to iterate through the segments one by one, retrieving all of the necessary data for each segment. This example uses PathIterator.Segment objects, which packages up the data for you:

KotlinJava
for (segment in pathIterator) {
    println("segment: ${segment.verb}, ${segment.points}")
}
while (pathIterator.hasNext()) {
    PathIterator.Segment segment = pathIterator.next();
    Log.i(LOG_TAG, "segment: " + segment.getVerb() + ", " + segment.getPoints());
}

PathIterator also has a non-allocating version of next() where you can pass in a buffer to hold the point data.

One of the important use cases of querying Path data is interpolation. For example, you might want to animate (or morph) between two different paths. To further simplify that use case, Android 14 also includes the interpolate() method on Path. Assuming the two paths have the same internal structure, the interpolate() method creates a new Path with that interpolated result. This example returns a path whose shape is halfway (a linear interpolation of .5) between path and otherPath:

KotlinJava
val interpolatedResult = Path()
if (path.isInterpolatable(otherPath)) {
    path.interpolate(otherPath, .5f, interpolatedResult)
}
Path interpolatedResult = new Path();
if (path.isInterpolatable(otherPath)) {
    path.interpolate(otherPath, 0.5F, interpolatedResult);
}

The Jetpack graphics-path library enables similar APIs for earlier versions of Android as well.

شبكات مخصّصة مع أدوات تظليل الأجزاء برأسي وأجزاء

منذ فترة طويلة، يتيح Android رسم شبكات مثلثية باستخدام تظليل مخصّص، ولكن كان تنسيق شبكة الإدخال يقتصر على بعض مجموعات السمات المحدّدة مسبقًا. يتيح نظام Android 14 استخدام الشبكات المخصّصة التي يمكن تحديدها على أنّها مثلثات أو شرائح مثلثية، ويمكن فهرستها اختياريًا. يتم تحديد هذه الشبكات باستخدام سمات مخصّصة وخطوات رؤوس العناصر المتغيّرة وبرامج تشويش رؤوس العناصر والعناصر الصغيرة المكتوبة بلغة AGSL.

يحدّد برنامج تظليل رؤوس المضلّعات المتغيّرات، مثل الموضع واللون، في حين يمكن لبرنامج تظليل العناصر تحديد لون البكسل اختياريًا، عادةً باستخدام المتغيّرات التي أنشأها برنامج تظليل رؤوس المضلّعات. إذا كان اللون مقدَّمًا منshader القطعة، يتم دمجه بعد ذلك مع Paint اللون الحالي باستخدام وضع الدمج الذي تم اختياره عند رسم الشبكة. يمكن تمرير المتجانسات إلى برامج تظليل الشرائح والرؤوس للحصول على مرونة إضافية.

عارض المخزن المؤقت للأجهزة للوحة الرسم

To assist in using Android's Canvas API to draw with hardware acceleration into a HardwareBuffer, Android 14 introduces HardwareBufferRenderer. This API is particularly useful when your use case involves communication with the system compositor through SurfaceControl for low-latency drawing.