0

As my image Uri uses a different way to make sure the App pivture is safe. It changes everytime when I request. For example, it may be like this

and next time it comes like this

As universal image loader uses the Uri as key for SD Chche . The image Uri changes for the end of the Uri I want to use only this part as key
I searched for a long time but still don`t get the answer. So please help me

inquisitive
  • 3,738
  • 6
  • 30
  • 56
Bob King
  • 3
  • 2

1 Answers1

3

This issue is pretty simple to change. Nostra's universal image loader uses a interface "FileNameGenerator" with the method "generate" in com.nostra13.universalimageloader.cache.disc.naming; Just create or adapt a class there and use this for your purpose. E.g. change HashCodeFileNameGenerator to:

 public class HashCodeFileNameGenerator implements FileNameGenerator {
@Override
public String generate(String imageUri) {
    return String.valueOf(imageUri.substr(0, imageUri.indexOf("=")).hashCode());
}
 }

The code above would generate a filename based on the image url till the first occurence of the sign '='.

alex
  • 5,516
  • 2
  • 36
  • 60
  • Wow thks man~!It works !ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder( getApplicationContext()) .discCacheFileNameGenerator(new HashCodeFileNameGenerator())//your FileNameGenerator .build(); Thanks again! – Bob King Aug 10 '13 at 03:19
  • Can you please mark the topic as solved with the green apply button on the left? – alex Aug 11 '13 at 20:38
  • I am very new here sorry~!I will do it – Bob King Aug 12 '13 at 02:59