Android图片缓存

来源:互联网 发布:知行结合爱国 编辑:程序博客网 时间:2024/05/22 00:51

在很多的APP开发中都会用到图片缓存,最近我也是用到了图片缓存的功能,这里做一下笔记,方便以后使用。

1、在开始的版本中时间缓存图片版存到本地指定SD卡路径下,代码部分由于最近没有时间,还没有整理出来,而且网上也有很多这部分的代码。

这样缓存会发现在图片浏览器或选择图片时,也会看到我们的缓存图片,体验效果很差。

解决方法:

a)将缓存图片保存为非图片格式的文件;

b)文件夹下添加.nomedia文件,这样可以将文件夹对于图片浏览器隐藏。

//得到图片缓存文件夹路径File file = new File(Environment.getExternalStorageDirectory() + Constants.IMAGE_SAVE_PATH + "/");//获取文件路径File file1 = new File(Environment.getExternalStorageDirectory() + Constants.IMAGE_SAVE_PATH + "/.nomedia");try {if (!file1.exists()) {//判断文件是否存在//创建文件new File(file, ".nomedia").createNewFile();}} catch (IOException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}
2、参考郭大神的图片缓存方法

http://blog.csdn.net/guolin_blog/article/details/34093441

0 0