Storing the image as a blob in the file system

I saved the images in the database in the blob field, but due to poor performance and 1 MB limit, I decided to switch to the file system. I am worried about a few things. Where do I specifically store images? Just create a folder and put it inside? Will it be visible to the user with file explorer? I am worried because I might lose the link to all this data if it is deleted from the user.

0
source share
2 answers

You can use the Android cache directory, which is usually located in / Android / data / YOURPACKAGENAME / cache

Use this code to get this path.

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

Displaying bitmaps efficiently; check out this example provided by Google, very useful if your goal is to cache images from the Internet. However, it is displayed to the user and can be easily removed.

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

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

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

Storage options

+2
source

Yes, this folder will be visible to the user. But if you are afraid that the user may delete this folder, than hide the folder. To hide the folder, run the name of the folder with a period (.).

0
source

Source: https://habr.com/ru/post/1242524/


All Articles