"how to priorly get future glide image size which will be stored in cache in android/java?" Code Answer

3

better to preload all the images with .downloadonly() instead of using any target. then load images using fileprovider.

private class cacheimage extends asynctask<string,void,file> {
        @override
        protected file doinbackground(string... strings) {
            try {
                return glide.with(getcontext())
                        .load(strings[0])
                        .downloadonly(target.size_original,target.size_original)
                        .get();
            } catch (exception e) {
                log.e(log_tag,e.getmessage());
                return null;
            }
        }

        @override
        protected void onpostexecute(file file) {
            if(file!=null){
               uri file_uri = fileprovider.geturiforfile(getcontext(),
                        getcontext().getpackagename()+".images",file);
            }
        }
    }

and store the path alongside url in sqlite. now get the image_url using fileprovider from sqlite

glide.with(imageview.getcontext())
                .load(<image_url>)
                .asbitmap()
                .dontanimate()
                .centercrop()
                .override(<width>,<height>)
                .priority(priority.immediate)
                .diskcachestrategy(diskcachestrategy.source)
                .skipmemorycache(true)
                .into(imageview);

you may also need to add,

in manifest, inside <application>

<provider
        android:name="android.support.v4.content.fileprovider"
        android:authorities="{app package name}.images"
        android:exported="false"
        android:granturipermissions="true">
        <meta-data
            android:name="android.support.file_provider_paths"
            android:resource="@xml/file_paths" />
    </provider>

inside res/xml, as file_paths.xml,

<paths xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <cache-path name="images" path="image_manager_disk_cache"
        tools:path="diskcache.factory.default_disk_cache_dir" />
</paths>
By Ezekiel Rage on May 26 2022

Answers related to “how to priorly get future glide image size which will be stored in cache in android/java?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.