다음 단계에서는 웹 URI에서 아트를 다운로드하여 로컬 URI를 통해 노출하는 방법을 설명합니다. 전체 예는 범용 Android 뮤직 플레이어 샘플 앱에서 openFile구현과 주변 메서드를 참고하세요.
웹 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()}
자바
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를 사용합니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-08-22(UTC)
[null,null,["최종 업데이트: 2025-08-22(UTC)"],[],[],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."]]