Caching files

Discussion in 'Android Hacks and Help' started by mzimmer74, Oct 22, 2010.

  1. mzimmer74

    mzimmer74 New Member

    Oct 22, 2010
    Likes Received:
    Trophy Points:
    Hi all,
    I'm new to the Droid (came from Windows mobile) and want to get into programming for it. I'm slowly working my way through the various possibilities and have managed to write a program that downloads an image from a web page and displays it on my screen. However, what I'd like to do is make a local copy of it so when I next run the program it doesn't have to download it again. Now, I know that I could just save it to a file, but I came across an older suggestion on a web site to use the System Cache. They recommend doing this:

    URL url = new URL(strUrl);
    URLConnection connection = url.openConnection();
    Object response = connection.getContent();
    if (result instanceof Bitmap) {
      Bitmap bitmap = (Bitmap)response;
    Now, it seems like they were saying that this would use the System Cache to automatically save the file and then if I were to call the same method with the same URL it would check the cache first and then download if needed. However, I can't get it to work. I keep getting an exception thrown and can't trace it back to where it's happening (Eclipse won't give me enough info). All I changed in my code was to replace my previous "LoadImage" method with the above.

    Here's my questions:
    1. Is the above code a legitimate way to load the image?
    2. If so, is there possibly a permission that I'm missing?
    3. In general, what Uses-Permission do I need to give to my applications to enable them to manipulate the filesystem?
    4. Is there some better way to accomplish what I'm trying to do?

    Thanks for any help.
Search tags for this page

android cache viewer