android - how to cache an image from a remote site
- by Lynnooi
Hi,
Can anyone please provide me some example on how to save an image i fetch from websites into a cache. I had try to include the following function into my code and call it once i run the activity.
public void getRemoteImage(String imageUrl) {
imageUrl = "http://marga.mobile9.com/download/thumb/295/sexylady7_xo6npovn.jpg";
URL aURL = null;
URLConnection conn = null;
Bitmap bmp = null;
CacheResult cache_result = CacheManager.getCacheFile(imageUrl, new HashMap());
if (cache_result == null) {
try {
aURL = new URL(imageUrl);
conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
cache_result = new CacheManager.CacheResult();
CacheManager.saveCacheFile(imageUrl, cache_result);
} catch (Exception e) {
//return null;
}
}
bmp = BitmapFactory.decodeStream(cache_result.getInputStream());*/
Toast.makeText(context,"Please work.. namo namo namo", Toast.LENGTH_SHORT).show();
//return bmp;
}
However, I got a nullPointerException. Can someone please help me with it as i'm quite new in android.