Adarsh
Adarsh

Reputation: 2279

Android: Universal Image Loader - Add new image to cache

I am successfully integrate Universal Imageloader in my Gallery App to show the images from the phone storage

But new images (captured from the camera /processed images) stored in the app's specified folder doesn't appear in the gallery. even the application restarted.

May be due to this error

W/ImageLoader: Try to initialize ImageLoader which had already been initialized before. To re-init ImageLoader with new configuration call ImageLoader.destroy() at first.

I think add the details of new image to the cache will resolve the problem. but don't know how . please help

code : Activity Extends Application

DisplayImageOptions defaultDisplayImageOptions = new DisplayImageOptions.Builder() //
        .considerExifParams(true)
        .resetViewBeforeLoading(true)
        .showImageOnLoading(R.drawable.nophotos)
        .showImageOnFail(R.drawable.nophotos)
        .delayBeforeLoading(0)
        .build(); //

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
        getApplicationContext())
        .defaultDisplayImageOptions(defaultDisplayImageOptions)
        .memoryCacheExtraOptions(480, 800).threadPoolSize(5)
        .build();


ImageLoader.getInstance().init(config);

load all album

   PhoneMediaControl mediaControl = new PhoneMediaControl();
    mediaControl.setLoadalbumphoto(new loadAlbumPhoto() {

        @Override
        public void loadPhoto(ArrayList<AlbumEntry> albumsSorted_) {
            albumsSorted = new ArrayList<PhoneMediaControl.AlbumEntry>(albumsSorted_);
            if (mView != null && mView.getEmptyView() == null) {
                mView.setEmptyView(null);
            }
            if (listAdapter != null) {
                listAdapter.notifyDataSetChanged();
            }
        }
    });
    mediaControl.loadGalleryPhotosAlbums(mContext, 0);

is there any way to add new processed image to the cache or already initiated imageloader

Upvotes: 0

Views: 894

Answers (3)

Adarsh
Adarsh

Reputation: 2279

I found this will reslove the problem using the function loadImageSync();

ImageLoader.getInstance().loadImageSync(filepath);

Upvotes: 0

Sohail Zahid
Sohail Zahid

Reputation: 8149

You just have to load the your image with universal image loader it will automatically cache it.

Loading

                ImageLoader imageLoader = ImageLoader.getInstance();
                Uri uri = Uri.fromFile(new File("/DCIM/Camera/1470634175974.jpg"));
                imageLoader.loadImage(uri.toString(), new SimpleImageLoadingListener() {

                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                        // Do whatever you want with Bitmap
                    }
                });

UNIVERSAL IMAGE LOADER ACCEPTED URI schemes

"file:///mnt/sdcard/image.png" // from SD card
"file:///mnt/sdcard/video.mp4" // from SD card (video thumbnail)
"content://media/external/images/media/13" // from content provider
"content://media/external/video/media/13" // from content provider (video thumbnail)
"assets://image.png" // from assets
"drawable://" + R.drawable.img // from drawables (non-9patch images)

Upvotes: 2

Ugurcan Yildirim
Ugurcan Yildirim

Reputation: 6142

Initialize your UniversalImageLoader instance only once inside onCreate() of your Application class, not inside each Activity or elsewhere.

Upvotes: 0

Related Questions