Search code examples
androiduniversal-image-loader

android universal image loader get Image with private/public secret key


I am using Universal Image loader to load images from server. But there is need to send private and public key along with Image URL to get the image from server. How to send private/public key along with URL to get image? OR How to send parameters in GET call using Universal Image Loader library Currently I am doing this without any parameters which is working fine..

//ImageLoader
ImageLoader imageLoader = ImageLoader.getInstance();
DisplayImageOptions displayImageOptions;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dashboard);
    uInit();

    //ImageLoader Initialization
    imageLoader.init(ImageLoaderConfiguration.createDefault(mContext)); 
    imageLoader = ImageLoader.getInstance();
    displayImageOptions = new DisplayImageOptions.Builder() 
    .cacheInMemory(true)
    .considerExifParams(true)
    .bitmapConfig(Bitmap.Config.RGB_565)
    .build();           

    String imgUrl = Commons.CURRENT_ACTIVE_PROFILE.getPhoto();
    imgUrl = Urls.base_url_without_app_keyword + imgUrl;        
    if(imgUrl!=null && !imgUrl.isEmpty())
        loadUserProfileImage(imgUrl); 

}

private void loadUserProfileImage(String imgUrl) {  
    // TODO Auto-generated method stub
    imageLoader.displayImage(imgUrl, userProfileImg, displayImageOptions, new SimpleImageLoadingListener() 
    { 
         @Override
         public void onLoadingStarted(String imageUri, View view) {

         }

         @Override
         public void onLoadingFailed(String imageUri, View view,
                 FailReason failReason) {

         }

         @Override
         public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {


         }
     }, new ImageLoadingProgressListener() 
     {
         @Override
         public void onProgressUpdate(String imageUri, View view, int current,
                 int total) {
         }
     });
}

Solution

  • You can use "extra for downloader" for that purpose. and pass key in header

    Map<String, String> headers = ...
     DisplayImageOptions options = new DisplayImageOptions.Builder()
        ...
        .extraForDownloader(headers)
        ...
        .build();
    

    Then create your own ImageDownloader which handles these headers:

    Refer this link https://github.com/nostra13/Android-Universal-Image-Loader/issues/340

    Hope it will help...