简体   繁体   中英

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

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)

仅在Application类的onCreate()中初始化一次UniversalImageLoader实例,而不在每个Activity或其他地方初始化一次。

我发现这可以使用loadImageSync()函数解决问题。

ImageLoader.getInstance().loadImageSync(filepath);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM