0

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

Adarsh
  • 2,219
  • 2
  • 23
  • 37

3 Answers3

2

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)
Sohail Zahid
  • 8,099
  • 2
  • 25
  • 41
0

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

Ugurcan Yildirim
  • 5,973
  • 3
  • 42
  • 73
  • Thanks .. It's only initiated once.. i need to add the new processed/saved image to the already initiated imageloader... is that possible – Adarsh Aug 09 '16 at 08:16
  • What do you mean by adding image to imageloader? The library automatically caches loaded images if you configure it so. – Ugurcan Yildirim Aug 09 '16 at 08:22
0

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

ImageLoader.getInstance().loadImageSync(filepath);
Adarsh
  • 2,219
  • 2
  • 23
  • 37