Search code examples
androidimagecachingasynchronousuniversal-image-loader

Get Android Universal Image Loader cache/save images with file extension


I am using the Android-Universal-Image-Loader from https://github.com/nostra13/Android-Universal-Image-Loader to load and cache images async. The problem I am facing is that i would like to open the images with the gallery or sent them to friends. For some reason my images are cached without a file extension.

I am using the current configuration

public static void initImageLoader(Context context) {

        File cacheDir = StorageUtils.getOwnCacheDirectory(context, CommonUtilities.APP_DIR);

        DisplayImageOptions options = new DisplayImageOptions.Builder()
        .cacheInMemory(true)
        .cacheOnDisc(true)
        .considerExifParams(true)
        .build();

        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
                .threadPriority(Thread.MAX_PRIORITY)
                .discCacheExtraOptions(480, 800, CompressFormat.PNG, 75, null)
                .denyCacheImageMultipleSizesInMemory()
                .discCache(new UnlimitedDiscCache(cacheDir))
                .defaultDisplayImageOptions(options)
                .tasksProcessingOrder(QueueProcessingType.FIFO)
                .build();

        // Initialize ImageLoader with configuration.
        ImageLoader.getInstance().init(config);
    }

Hopefully anyone can help me out!


Solution

  • Create own FileNameGenerator which will generate file names with extension in the end and then set it into disc cache:

        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
                 ...
                .discCache(new UnlimitedDiscCache(cacheDir, myGenerator))
                ...
                .build();