何处保存在Android上的图片? [英] Where to save pictures on Android?

查看:148
本文介绍了何处保存在Android上的图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序使用了相当多的是从网上下载并在Android手机本地缓存的图片。我想知道,什么是正确的方式来保存这些照片。还有我看到几个方式,是不完全令人满意。

My application uses quite a lot of pictures that are downloaded from the internet and cached locally on the Android phone. I am wondering, what is the correct way to save those pictures. There are several ways I see, that are not fully satisfying.

将它们保存在SD卡中的公用文件夹

Save them on SD Card in a public folder

  • 使用最多的空间,不会被释放的卸载
  • 用户可以看到图片的画廊
  • 需要对SD卡的根文件夹(你可以看到它在浏览你的手机)

将它们保存在SD卡在一个非公开的文件夹

Save them on SD Card in a non-public folder

  • 使用最多的空间,不会被释放的卸载
  • 在偷偷使用的SD卡空间

保存它们的应用程序里面

Save them inside the application

  • 在打击了应用程序的大小太多

什么是本地保存我的应用程序的图像不是分散的用户,并在任何地方留下任何垃圾的正确方法?

What is the correct way of locally saving the images of my application to not distract the user and leave no garbage anywhere?

推荐答案

您最好的解决办法是使用:

Your best solution is to use:

context.getCacheDir()

这个目录是私有的应用程序和卸载都将被删除,此外,该系统可以从这个目录中你,如果设备运行缺乏空间删除。

This directory is private to the application and will be deleted on uninstall, furthermore the system can delete from this directory for you if the device is running short of space.

请注意,虽然该文档说:

Note though that the docs say:

你不应该靠制度   删除这些文件给你;您   应该始终有一个合理的   最大,如1 MB表示,量   空间占用使用缓存文件,   并超过修剪时,这些文件   空间

you should not rely on the system deleting these files for you; you should always have a reasonable maximum, such as 1 MB, for the amount of space you consume with cache files, and prune those files when exceeding that space

如果你需要一个很大的空间,而宁愿使用SD卡,您可以拨打

If you need a lot of space and would rather use the SD card you can call

getExternalCacheDir()

来代替。这些也将获得在卸载删除,但系统没有监控外部存储的可用空间,这样就不会自动删除,如果空间不足,这些文件。如果使用此选项,您也应该检查外部存储可与

instead. These will also get removed on uninstall, but the system does not monitor the space available in external storage, so won't automatically delete these files if low on space. If using this option you should also check that external storage is available with

Environment.getExternalStorageState()

在试图写它。

这篇关于何处保存在Android上的图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆