문제

I have been storing images in database in a blob field, but because of bad performance and 1MB cursor limit, I decided to switch to file system. I am concerned about few things. Where do I specifically store the images? Just create a folder and put them inside ? Will that be visible to the user with file explorers? I am worried because I might lose reference to all these if they were to be deleted from the user.

도움이 되었습니까?

해결책

You can use Android's cache directory, it's generally 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, 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.

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

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

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

Storage Options

다른 팁

yes that folder will be visible to user. But if you are worried that user can delete that folder than hide the folder. To hide the folder begin the name of folder with dot(.) .

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top