且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

存储图像在文件系统中的BLOB

更新时间:2023-11-29 13:54:52

您可以使用Android的缓存目录,它通常位于/ Android的/数据/ YOURPACKAGENAME /缓存

You can use Android's cache directory, it's generally located in /Android/data/YOURPACKAGENAME/cache

使用此code得到此路径。

Use this code to get this path.

最后弦乐cachePath =
  Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
  ||
                          !isExternalStorageRemovable()? getExternalCacheDir(上下文).getPath():
                                  。context.getCacheDir()的getPath();

final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !isExternalStorageRemovable() ? getExternalCacheDir(context).getPath() : context.getCacheDir().getPath();

显示位图高效检查由谷歌提供这个例子中,是,如果你的目标是从Web缓存图像非常有用。然而,它是用户可见和可容易地删除。

Displaying Bitmaps Efficiently check out this example provided by Google, it is very useful if your goal is to cache images from the web. However it is visible to the user and can be easily deleted.

如果你想隐藏的用户此文件,你可以简单地保存文件,而无需任何路径,这将是内部的数据/数据​​/ YOURPACKAGENAME,这是从用户隐藏,直到用户具有root访问权限。
示例

If you want to hide this files from user, you can simply save files without any path, it will be inside data/data/YOURPACKAGENAME, which is hidden from users until user has root access. Example

字符串文件名=hello_file;
串串=世界,你好!

String FILENAME = "hello_file"; String string = "hello world!";

FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();

存储选项