对外部存储器/ SD卡缓存图像推荐路径 [英] Recommended path for caching images on external memory / sd card

查看:127
本文介绍了对外部存储器/ SD卡缓存图像推荐路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我看在Android的文件传输或天文文件管理器,我的SD卡根目录是一个烂摊子,因为应用程序是存储文件所有的地方。

When I look at my sd card root directory in Android file transfer or Astro file manager it's a mess because apps are storing files all over the place.

作为开发人员,我们遵循最佳实践,通过缓存图像/文件等,以使我们的应用程序更快,我们使用 Environment.getExternalStorageDirectory()来获得外部存储设备的根目录下(没有硬编码/ SD卡)。但是,应该去下一个?理想的世界里,我们会遵循倾倒在田野是外部存储我们的缓存文件的约定?

As developers we follow best practice by caching images/files etc to make our apps quicker and we use Environment.getExternalStorageDirectory() to get the root of the external storage (not hardcoding /sdcard). But what should go next? ideal world we'd follow a convention for dumping our cached files on the open field that is the external storage?

下面是几个我从我自己的设备/经验,看到的选项:

Here's a couple of the options I see from my own device/experience:

  • /。缓存/ APP_NAME /
  • /。APP_NAME /
  • /缓存/< APP_NAME> /
  • /数据/< APP_NAME> /
  • /com.package.name /
  • / APP_NAME /
  • /.cache/app_name/
  • /.app_name/
  • /cache/<app_name>/
  • /data/<app_name>/
  • /com.package.name/
  • /app_name/

我现在preFER第一个选项是默认隐藏的设备上的文件管理器。

I currently prefer the first option as hidden by default from on device file managers.

有谁知道后面几个流行/大牌的应用程序从谷歌或公约的建议?或原因,这是一个坏主意?

Does anyone know of recommendations from Google or conventions followed by several popular/big names apps? or reasons this is a bad idea?

推荐答案

据开发者文档

保存缓存文件

如果您使用的是API级别8或更高,使用getExternalCacheDir()打开重新presents外部存储目录,你应该保存的缓存文件的文件。如果用户卸载应用程序,这些文件会被自动删除。然而,你的应用程序的生命周期内,您应该管理这些缓存文件并删除那些没有必要的,以preserve文件空间。

If you're using API Level 8 or greater, use getExternalCacheDir() to open a File that represents the external storage directory where you should save cache files. If the user uninstalls your application, these files will be automatically deleted. However, during the life of your application, you should manage these cache files and remove those that aren't needed in order to preserve file space.

如果您正在使用API​​ 7级或更低,使用getExternalStorageDirectory()打开重新$ P $文件psents外部存储的根目录,然后写缓存数据在以下目录:

If you're using API Level 7 or lower, use getExternalStorageDirectory() to open a File that represents the root of the external storage, then write your cache data in the following directory:

/安卓/数据/&LT;软件包名称> /缓存/

/Android/data/<package_name>/cache/

在&lt;软件包名称>是您的Java风格的包名,如com.example.android.app

The <package_name> is your Java-style package name, such as "com.example.android.app".

更多资讯

http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

希望它可以帮助

这篇关于对外部存储器/ SD卡缓存图像推荐路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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