How to make pictures taken by my App backup-able - android

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.

Related

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.

How do apps like Google Keep and Evernote save images?

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)

Save image in SQLite database from Android

I have a question about saving images in an SQLite database location in the app.
I made an app for iOS where users can snap a photo or grab an existing one from the app that saves them in a local bank in own app, since the IOS does not have so many problems with disk space.
On Android already have code that takes the photo or use an existing one, now wanted to know how save them in SQLite database. (?)
I've been reading about and some suggest saving the image in SD card and insert into the database only the image path, but if for some reason it is excluded from the SD card will have an error in your application for the path referenced no longer exists.
What would be the ideal solution for this?
You should only keep the name of the picture in the database and store the picture on the internal storage, not on the sdcard, save them in the first place as private to your application only.
The ideal solution is to store it in the SD card. Storing in DB won't keep the user from deleting it. You'll also lose this information if the user clears the app data. All databases are deleted when the user does it.
Anyway, if you choose the SQLite solution, you can use a blob field. Remember that some versions of SQLite won't support large blob data. Check this out:
http://effbot.org/zone/sqlite-blob.htm
I also suggest this:
http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html

storing data in device after the first time they are recalled android

I want to do this. my app has many screens and in each of them, on the top, I display an imageView as a logo. So I have 20 screens and that means (20*3) images in my drawable which makes my app be many Mb's. Because this image is static and never changes I want to do this: Getting it from the web (I know how to do it, I am not asking this) only for the first time this screen is ever launched, then this image be stored somewhere in user's device and then use that path as a source. (I mean not download it again, because it will be annoying for the user waiting every time). So is it possible? Will it make my app go slower (not the first time, but the rest) because I am retrieving data from SD?
Yes, you can do this fairly easily. You also do not have to store the data on the SD card necessarily. You can store the image in the internal storage.
Basically, set up a cache directory. When you need the image, check the cache directory, and if the file is not there, download it over http and store the file in the cache directory.
It will change how you get the resource (e.g., you won't be able to use R.drawable.imagename), but you can just load the drawable programmatically.

android: how to save an image in a object

What i want is that i have made a picture chooser, the image chosen i then want to save in my own object.
Like i have a class called personalFile, this file then includes all details, name, birthdate etc.. I have made it so i can update this personal file and save them to the external storage getExternalFilesDir() using an ObjectOutPutStream.
Now i have taken a picture of the person, and have browsed my way to the picture and gotten the uri path to the picture, now how do I save this file together with the rest of the information in my class?
I have tried looking but havnt found anyone doing this. The reason is also i'd like to be able to send the personal record to another phone using mms, email or alike and be able to open it there with the picture and all.
One way of doing it (albeit not the most efficient) would be to have a byte[] image; member variable in your class and read the content of your file into that byte array. You are quite likely to experience issues though if the image size is large. The other alternative would be to just copy the image file to your external storage and inside your class simply save the file name of the file. Either way, I'm not sure of the merit of saving images as part of your persistent app data (unless the images are really small).

Categories

Resources