تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يجب تمرير العمل الفني الخاص بعناصر الوسائط كمعرّف موارد منتظم (URI) محلي باستخدام ContentResolver.SCHEME_CONTENT أو ContentResolver.SCHEME_ANDROID_RESOURCE. يجب أن يؤدي معرّف الموارد المنتظم (URI) المحلي هذا إلى عرض إما صورة نقطية أو رسم متّجه في موارد التطبيق. بالنسبة إلى عناصر
MediaDescriptionCompat التي تمثّل عناصر في التسلسل الهرمي للمحتوى،
مرِّر معرّف الموارد المنتظم من خلال setIconUri.
بالنسبة إلى عناصر MediaMetadataCompat التي تمثّل العنصر الذي يتم تشغيله،
استخدِم أيًا من المفاتيح التالية لتمرير معرّف الموارد المنتظم (URI) من خلال putString:
توضّح هذه الخطوات كيفية تنزيل عمل فني من معرّف موارد موحّد (URI) على الويب وعرضه من خلال معرّف موارد موحّد (URI) محلي. للحصول على مثال كامل، راجِع عملية التنفيذ الخاصة بالرمز openFile والطُرق المحيطة به في نموذج تطبيق Universal Android Music Player.
أنشئ معرّف موارد منتظم (URI) content:// مطابقًا لمعرّف الموارد المنتظم (URI) على الويب. تمرِّر خدمة متصفّح الوسائط وجلسة الوسائط معرّف الموارد المنتظم (URI) الخاص بهذا المحتوى إلى Android Auto وAndroid Automotive OS (AAOS).
Kotlin
funUri.asAlbumArtContentURI():Uri{returnUri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(CONTENT_PROVIDER_AUTHORITY).appendPath(this.getPath())// Make sure you trust the URI.build()}
Java
publicstaticUriasAlbumArtContentURI(UriwebUri){returnnewUri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(CONTENT_PROVIDER_AUTHORITY).appendPath(webUri.getPath())// Make sure you trust the URI!.build();}
في عملية تنفيذ ContentProvider.openFile، تحقَّق مما إذا كان هناك ملف لمعرّف الموارد المنتظم (URI) المقابل. إذا لم يكن كذلك، نزِّل ملف الصورة واحفظه في ذاكرة التخزين المؤقت. يستخدم مقتطف الرمز هذا Glide.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-08-22 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-22 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Display media artwork\n\nArtwork for media items must be passed as a local URI using either\n[`ContentResolver.SCHEME_CONTENT`](/reference/android/content/ContentResolver#SCHEME_CONTENT) or\n[`ContentResolver.SCHEME_ANDROID_RESOURCE`](/reference/android/content/ContentResolver#SCHEME_ANDROID_RESOURCE). This local URI must resolve to\neither a bitmap or a vector drawable.\n\n- For `MediaDescriptionCompat` objects representing items in the [content\n hierarchy](/training/cars/media/create-media-browser/content-hierarchy#onLoadChildren), pass the URI through [`setIconUri`](/reference/android/support/v4/media/MediaDescriptionCompat.Builder#setIconUri(android.net.Uri)).\n\n | **Warning:** Don't provide artwork using [`setIconBitmap`](/reference/android/support/v4/media/MediaDescriptionCompat.Builder#setIconUri(android.net.Uri)). While this method is supported on Android Auto, it isn't supported on Android Automotive OS (AAOS). Additionally, including many bitmaps in a result can cause you to exceed the [1MB binder size limit](/guide/components/activities/parcelables-and-bundles#sdbp), causing your app to be unresponsive.\n- For `MediaMetadataCompat` objects representing the [playing item](/media/legacy/mediasession#maintain-state),\n use any of these keys to pass the URI through [`putString`](/reference/android/support/v4/media/MediaMetadataCompat.Builder#putString(java.lang.String,%20java.lang.String)):\n\n - [`MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON_URI`](/reference/android/support/v4/media/MediaMetadataCompat#METADATA_KEY_DISPLAY_ICON_URI())\n - [`MediaMetadataCompat.METADATA_KEY_ART_URI`](/reference/android/support/v4/media/MediaMetadataCompat#METADATA_KEY_ART_URI())\n - [`MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI`](/reference/android/support/v4/media/MediaMetadataCompat#METADATA_KEY_ALBUM_ART_URI())\n\nProvide artwork from your app's resources\n-----------------------------------------\n\nTo provide drawables from your [app's resources](/guide/topics/resources/providing-resources), pass a URI in the\nfollowing format: \n\n android.resource://\u003cvar translate=\"no\"\u003ePACKAGE_NAME\u003c/var\u003e/\u003cvar translate=\"no\"\u003eRESOURCE_TYPE\u003c/var\u003e/\u003cvar translate=\"no\"\u003eRESOURCE_NAME\u003c/var\u003e\n\n // Example URI - note that there is no file extension at the end of the URI\n android.resource://com.example.app/drawable/example_drawable\n\nThis snippet demonstrates how to create a URI of this format from a resource ID: \n\n val resources = context.resources\n val resourceId: Int = R.drawable.example_drawable\n\n Uri.Builder()\n .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)\n .authority(resources.getResourcePackageName(resourceId))\n .appendPath(resources.getResourceTypeName(resourceId))\n .appendPath(resources.getResourceEntryName(resourceId))\n .build()\n\nProvide artwork using a content provider\n----------------------------------------\n\nThese steps describe how to download art from a web URI and expose it through a\nlocal URI using a [content provider](/guide/topics/providers/content-provider-creating). For a complete example, see the\n[implementation](https://github.com/android/uamp/blob/99e44c1c5106218c62eff552b64bbc12f1883a22/common/src/main/java/com/example/android/uamp/media/library/AlbumArtContentProvider.kt#L52) of [`openFile`](/reference/android/content/ContentProvider#openFile(android.net.Uri,%20java.lang.String)) and the surrounding methods in the\nUniversal Android Music Player sample app.\n\n1. Build a `content://` URI corresponding to the web URI. The media browser\n service and media session pass this content URI to Android Auto and\n AAOS.\n\n ### Kotlin\n\n fun Uri.asAlbumArtContentURI(): Uri {\n return Uri.Builder()\n .scheme(ContentResolver.SCHEME_CONTENT)\n .authority(CONTENT_PROVIDER_AUTHORITY)\n .appendPath(this.getPath()) // Make sure you trust the URI\n .build()\n }\n\n ### Java\n\n public static Uri asAlbumArtContentURI(Uri webUri) {\n return new Uri.Builder()\n .scheme(ContentResolver.SCHEME_CONTENT)\n .authority(CONTENT_PROVIDER_AUTHORITY)\n .appendPath(webUri.getPath()) // Make sure you trust the URI!\n .build();\n }\n\n2. In your implementation of `ContentProvider.openFile`, check if a file exists\n for the corresponding URI. If not, download and cache the image file. This\n code snippet uses [Glide](https://github.com/bumptech/glide).\n\n ### Kotlin\n\n override fun openFile(uri: Uri, mode: String): ParcelFileDescriptor? {\n val context = this.context ?: return null\n val file = File(context.cacheDir, uri.path)\n if (!file.exists()) {\n val remoteUri = Uri.Builder()\n .scheme(\"https\")\n .authority(\"my-image-site\")\n .appendPath(uri.path)\n .build()\n val cacheFile = Glide.with(context)\n .asFile()\n .load(remoteUri)\n .submit()\n .get(DOWNLOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS)\n\n cacheFile.renameTo(file)\n file = cacheFile\n }\n return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY)\n }\n\n ### Java\n\n @Nullable\n @Override\n public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode)\n throws FileNotFoundException {\n Context context = this.getContext();\n File file = new File(context.getCacheDir(), uri.getPath());\n if (!file.exists()) {\n Uri remoteUri = new Uri.Builder()\n .scheme(\"https\")\n .authority(\"my-image-site\")\n .appendPath(uri.getPath())\n .build();\n File cacheFile = Glide.with(context)\n .asFile()\n .load(remoteUri)\n .submit()\n .get(DOWNLOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS);\n\n cacheFile.renameTo(file);\n file = cacheFile;\n }\n return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);\n }\n\n| **Note:** The content URI should be quickly constructed and sent to Android Auto and AAOS, as demonstrated in the previous example. This is true even when the file isn't downloaded. Android Auto and AAOS show a loading UI for the images when waiting for the content provider to respond. Consider optimizing your app to quickly fetch images and to minimize the time needed to load the UI. Consider preloading and caching images."]]