1. DroidForums.net is currently undergoing a major software upgrade. If you are experiencing any problems logging in please: Contact Us

Caching files

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

  1. mzimmer74
    Offline

    mzimmer74 New Member

    Joined:
    Oct 22, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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:

    Code:
    URL url = new URL(strUrl);
    URLConnection connection = url.openConnection();
    connection.setUseCaches(true);
    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