How do apps like Google Keep and Evernote save images? - android

I am interested in how the mechanics of several note taking apps work. Many of them allow the user to add images and similar to notes. I know that it's possible to save the note's text etc. into a database, but how and where are the images being stored?
What is the most convenient way to achieve this? My guess was that a thumbnail or a compressed file gets created and saved in a certain directory, then the file's path will be stored to the database.

these apps may use external directories, but there is also a way to store data (as bytes, column type named BLOB) directly in database. check out this question-answer for more info
note that storing large size files in database isn't most efficient way.
if you want to know how these apps are storing images root your device and use SQLite debugger (or other way) to look into other apps databases (then you may find above mentioned BLOB columns). or check your device storage (internal and external) for folders with these image files (oftenly apps are creating folders with . in theirs filename, which in Unix based systems mean that folder is hidden)

Related

How to make pictures taken by my App backup-able

Lets say I have an App that allows me to rate mugs. Therefore, I enter some rating criterias, take a Picture of the mug and then save it to a DataBase, to look at it later.
At the moment, I save the picture on a path obtained by
getExternalFilesDir(Environment.DIRECTORY_PICTURES)
and save the path to my SQLite database to look at it later.
This works fine, however, as I rate a hole bunch of mugs all day and change my phone quiet often, I want to be able to backup my App and its data by common Android backup solutions. This works fine with the SQLite Database that holds the data and is stored in App-Context.
But since the database just holds a path to the taken picture (as returned by getExternalFilesDir), the picture is not backed-up. Where do I have to save the picure, to ensure that any common Android backup software will also grap the pictures?
Is it possible to ensure that the path stored in the database is the same, after I put the backup on a new phone? Since it may be possible that the App is located somewhere else on the new phone, absolute paths are not a good idea here... Is it possible to save the picture relative to the App and just save the relative path?
As suggested by greenapps, a possible solution is to save just the relative path of the image in the database. Instead of using
getExternalFilesDir(Environment.DIRECTORY_PICTURES)
I now use
getFilesDir()
to get the app intern folder and save images there. When I want to load the picture I build the path with the same method to get the app dir and the relative path saved in the database.

What is the best way to store the image in the memory of app?

I'm using sqlite db in my app and now I would like to allow user customize the background image make them able to select one from their gallery.
Should I just store the path to image and simpy refer to it every time or should I some how transfer the image to some text and store it completely in my db? The second option prevents in case of picture being deleted from gallery. But I would like to know the most appropriate way of doing that.
SQLite has a cursor limit of 1Mb. So, you will probably not be able to store it completely in the DB, when you go to to request it will probably be truncated. Store the path to the image in the database table, and access it that way.
You wouldn't store it as text. Store it as blob to your database. In my opinion this is the way to go (if you use SQLite anyway).
If you have large images then store the path to your storage and not the image to the database.
I think it would be better to save only the path of the background, you won't be limited by the size of the image
In my opinion, the best way to save the customized background image is copy it into the internal storage (private storage) of your application. If you store only the path of the file, then file cannot be available once the user deleted that.
The official docs saying about the internal storage is:
It's always available.
Files saved here are accessible by only your app by default.
When the user uninstalls your app, the system removes all your app's files from internal storage.

Can we store .doc .pdf and .jpg files in SQLite Database (Android)?

Is it possible to store files like pdf doc in SQLite db and the retrieve them again successfully.the files must be intact and readable again.I know we can store image files but for the above??.
Even if we can store what will be the given max file size??
Yes, go ahead. It is easier to store every file in the database, than just using the database to keep track of where each file is.
If the files are small, performance should be fine. From the SQLite website:
... many developers are surprised to learn that SQLite can read and write smaller BLOBs (less than about 100KB in size) from its database faster than those same blobs can be read or written as separate files from the filesystem. (See 35% Faster Than The Filesystem and Internal Versus External BLOBs for further information.) There is overhead associated with operating a relational database engine, however one should not assume that direct file I/O is faster than SQLite database I/O, as often it is not.
I know we can store image files but for the above?
From the standpoint of SQLite, an image is no different than any other type of file. You are welcome to store file contents in a BLOB column. This may not be very efficient.
Even if we can store what will be the given max file size?
The limit of a SQLite database is something like 2TB. Your Android device will not have that much storage space.
SQLite is a liteweight component.
Instead of storing files like .pdf and .doc in SQLite,store them in internal storage and get the path in internal storage and now store that in SQLite as a string.

Best way to organize editable internal data files for Android app?

I want to use data from an xml file to populate AutoCompleteTextViews and MultiAutoCompleteTextViews, and I also want to be able to edit this file while the app is running so that the AutoCompleteTextViews can be updated with new information. What is the best way to go about this? I know that files in the /res folder cannot be written to during runtime, and writing to external storage is slower than accessing internal storage.
One way you could do this is by creating your own SQLite database.
I would make sure that the scope of what you are doing merits a database, though.
The other option is just to create a flat file with keyValuePairs and look up the value with the view's ID as the key. This could be stored in external storage. Access speed should not be a big concern for a text file.

Where to safely put large data in android

I have to store a lot of images that have to be downloaded from the web server. The size of the images might be 80Mb. So I want a guidance where to store them, whether in internal or external storage. Both create some problems for me. Internal storage is as every one knows is very limited but the problem with external storage is that images can be accessed by user. I don't wanna my application images to be exposed to user and changed or deleted. So is there any alternative or is there any technique to safely put data into external storage?
Unfortunately no, external storage has FAT file system, which does not support access restriction. And you simply must not store such large chunks of data in internal memory (or otherwise users will not like you, to put it mildly).
So the only way to go, is to use external storage. If you need some protection, then you may either encrypt/decrypt data. Or just obfuscate data, like changing file extensions, or adding 10 bytes at the beginning of each file. Obfuscation is more efficient resource-wise, but much less protected. Though encryption key can still be extracted from your application, so both of this approaches have their flows.
I would advice to store them in the external storage. If you don't want the user to be able to read it, protect it with an encryption. I think it's a bad idea to impose large data to the user. If the user wants to remove it, you shouldn't want to prevent it. Perhaps consider the possibility of re-download the pictures from the web if it has been deleted.
Use encryption for file content:
i found nice and lightweight sample code on http://www.androidsnippets.com/encryptdecrypt-strings
I recommend saving to external. Preventing the user from deleting his data is not recommended. Also user can format the sdcard to delete it. so you cannot stop the user. You can hide it from him. Just prefix a dot to the folder name to make it hidden.
If you are using Android 2.3, OBB is your choice.
http://developer.android.com/reference/android/os/storage/StorageManager.html
OBBs contain a filesystem that maybe be encrypted on disk and mounted on-demand from an application. OBBs are a good way of providing large amounts of binary assets without packaging them into APKs as they may be multiple gigabytes in size. However, due to their size, they're most likely stored in a shared storage pool accessible from all programs. The system does not guarantee the security of the OBB file itself: if any program modifies the OBB, there is no guarantee that a read from that OBB will produce the expected output.
Related
What is OBB(Opaque Binary Blob) in Android develop site?

Categories

Resources