মিডিয়া আইটেমগুলির জন্য আর্টওয়ার্ক অবশ্যই একটি স্থানীয় URI হিসাবে ContentResolver.SCHEME_CONTENT বা ContentResolver.SCHEME_ANDROID_RESOURCE ব্যবহার করে পাস করতে হবে। এই স্থানীয় URI-কে অবশ্যই একটি বিটম্যাপ বা ভেক্টর অঙ্কনযোগ্য সমাধান করতে হবে।
MediaDescriptionCompatবস্তুর জন্য বিষয়বস্তু অনুক্রমের আইটেম প্রতিনিধিত্ব করে,setIconUriমাধ্যমে URI পাস করুন।প্লেয়িং আইটেম প্রতিনিধিত্বকারী
MediaMetadataCompatঅবজেক্টের জন্য,putStringমাধ্যমে URI পাস করতে এই কীগুলির যেকোনো একটি ব্যবহার করুন:
আপনার অ্যাপের সম্পদ থেকে আর্টওয়ার্ক প্রদান করুন
আপনার অ্যাপের সংস্থানগুলি থেকে অঙ্কনযোগ্য প্রদান করতে, নিম্নলিখিত বিন্যাসে একটি URI পাস করুন:
android.resource://PACKAGE_NAME/RESOURCE_TYPE/RESOURCE_NAME
// Example URI - note that there is no file extension at the end of the URI
android.resource://com.example.app/drawable/example_drawable
এই স্নিপেটটি দেখায় কিভাবে একটি রিসোর্স আইডি থেকে এই ফরম্যাটের একটি URI তৈরি করতে হয়:
val resources = context.resources
val resourceId: Int = R.drawable.example_drawable
Uri.Builder()
.scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
.authority(resources.getResourcePackageName(resourceId))
.appendPath(resources.getResourceTypeName(resourceId))
.appendPath(resources.getResourceEntryName(resourceId))
.build()
একটি বিষয়বস্তু প্রদানকারী ব্যবহার করে শিল্পকর্ম প্রদান
এই পদক্ষেপগুলি বর্ণনা করে যে কীভাবে একটি ওয়েব URI থেকে আর্ট ডাউনলোড করতে হয় এবং একটি বিষয়বস্তু প্রদানকারী ব্যবহার করে একটি স্থানীয় URI-এর মাধ্যমে এটি প্রকাশ করতে হয়। একটি সম্পূর্ণ উদাহরণের জন্য, ইউনিভার্সাল অ্যান্ড্রয়েড মিউজিক প্লেয়ার নমুনা অ্যাপে openFile এবং আশেপাশের পদ্ধতির বাস্তবায়ন দেখুন।
ওয়েব ইউআরআই-এর সাথে সম্পর্কিত একটি
content://URI তৈরি করুন। মিডিয়া ব্রাউজার পরিষেবা এবং মিডিয়া সেশন এই কন্টেন্ট URIকে Android Auto এবং AAOS-এ পাস করে।কোটলিন
fun Uri.asAlbumArtContentURI(): Uri { return Uri.Builder() .scheme(ContentResolver.SCHEME_CONTENT) .authority(CONTENT_PROVIDER_AUTHORITY) .appendPath(this.getPath()) // Make sure you trust the URI .build() }জাভা
public static Uri asAlbumArtContentURI(Uri webUri) { return new Uri.Builder() .scheme(ContentResolver.SCHEME_CONTENT) .authority(CONTENT_PROVIDER_AUTHORITY) .appendPath(webUri.getPath()) // Make sure you trust the URI! .build(); }আপনার
ContentProvider.openFileএর বাস্তবায়নে, সংশ্লিষ্ট URI-এর জন্য একটি ফাইল বিদ্যমান কিনা তা পরীক্ষা করুন। যদি না হয়, ডাউনলোড করুন এবং ইমেজ ফাইল ক্যাশে. এই কোড স্নিপেট গ্লাইড ব্যবহার করে।কোটলিন
override fun openFile(uri: Uri, mode: String): ParcelFileDescriptor? { val context = this.context ?: return null val file = File(context.cacheDir, uri.path) if (!file.exists()) { val remoteUri = Uri.Builder() .scheme("https") .authority("my-image-site") .appendPath(uri.path) .build() val cacheFile = Glide.with(context) .asFile() .load(remoteUri) .submit() .get(DOWNLOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS) cacheFile.renameTo(file) file = cacheFile } return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY) }জাভা
@Nullable @Override public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException { Context context = this.getContext(); File file = new File(context.getCacheDir(), uri.getPath()); if (!file.exists()) { Uri remoteUri = new Uri.Builder() .scheme("https") .authority("my-image-site") .appendPath(uri.getPath()) .build(); File cacheFile = Glide.with(context) .asFile() .load(remoteUri) .submit() .get(DOWNLOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS); cacheFile.renameTo(file); file = cacheFile; } return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY); }