Android data (text+image) storage - android

I want to create an android application containing the following data:
Text in four different languages, a date and an image.
My problem is that I don't know the best way to store those data. They should be available for the lambda user but not easily visible (--> not on the sd card for example). Without image, I would directly have chosen sqlite but... with it, whats the best?
assets? sqlite(+ image as blob)? sqlite(+ path to image)? XML? JSON?
Also, I want to randomly pick one of my about 1000 entries and thos entries will probably be inserted by someone who has low computer science knowledges.

The files that are stored inside your application folder are private to your application and cannot be easily accessed.
So easiest would be to have the text as xml and images as assets inside your app folder.

If the images are static (ie.. not downloaded but distributed with your app) I would put these in assets (drawable).
With regards to the text, you could use strings.xml and localize this for the other 3 languages.
Hope I have understood your problem here.

Related

I want to create a holy book app on my religion but problem with large amount of texts

I am trying to create holy book app in android studio, but this requires a large amount of texts.
The problem occurs when I paste those texts in strings.xml it shows an error like TF8 representation for string is too long for the constant pool. My question is is there any way to do that as many apps already done it but I don't know how. I want to show that text in my main activity as my app would have single activity.
Since it will contain a lot of texts, you can create multiple files for each "chapter" and read from the files as mentioned by Navin. Having multiple text or json files will help manage the texts easier.
Also you can use PDF file in Assets folder ,I think it will be more easier

How to store pictures paths from res/drawables folder?

I need to do an Quiz App with pictures associated to the questions.
The problem is that there should be default questions with the app and in future the app shall be able to create more questions and i dont know how to store the pictures paths on database mainly because of the default questions.
My first aproach is to have the default pictures in the res/drawables but how can i get the path of res/drawables pictures?
I hope to have explained my problem well.
Res/drawables doesn't have paths. They have integer ids. So there's no path to get. Those ids also change every compile, so hardcoding them isn't always ideal.
I would suggest that the first time you start up, you write those default images to disk. This gives you two benefits- one you have a path. Two, you can treat default images and non-default images with the exact same code.
Have a look on Android Save and Retrieve Image Path From Database

Store retrieve data (.txt) from SD card

Alright, here is my program and the problem:
My android app can take some texts and store it a local file. Lets say on an sd card. And it can categorize those file as well (create different folder, and save it there).
Now, my computer can run and write folders and .txt files, but I have no idea how to retrieve those in my list view. Let's say, my list view has two components, a textView and an Imageview, side by side. (And I want to retrieve those .txt files from my sd card, read a few words, and put them in the list in textView). You can consider it like a notepad with some features.
What I need to know now is how to read through all those data available in all of my sub-directories and put them in a list.(No need to explain about the imageView one, I can handle that, but want to know about .txt)
I know, I talk too much, but if you can guide me, I would really appreciate that.(Keep in mind that am still an amateur, so please explain the code you write or comment briefly)
Thanks in advance.

Seeking guidance: data storage decision

I apologize in advance if this question is too broad or too "it-depends."
Basically, I need to make a decision about how to store and access data in my app. The app works very much like flashcards; the "front" of the card presents the topic and the "back" presents the details/explanation. At first it seemed like a SQLite database would work best for this type of structure (and maybe it really is, I just don't know) because the data is static and this model works well with the rows and columns structure of a db. (btw, as of now, I'm using openCSV to parse the csv files containing my cards. Thought it was easier than SQLite...)
My issue (finally) is that I want to be able to display images for some of the data items. Some cards, for example, should display a corresponding image. Is this something that I can do with a SQLite db? Like, have one column store the path to an image....? Maybe what I'm asking is really basic, but I just haven't seen too many examples to really have a good sense of the design options out there.
I might also be confused about how I would dynamically change my views based on whether there is an image available. Maybe that's just an issue of dynamically creating an imageview whose source is the file that the db points to...
In summary, I'd really appreciate some guidance on how I can fetch and display text data along with images when they're available, whether it be in SQLite or some other way.
Thanks!
If all this data is being shipped with the app, I'd suggest just keeping everything stored as resources. You can have string arrays for the topics and details, and you can store images either as drawable resources or as assets. In the latter case, you could store the asset names as another string array resource. (In the former case, you'd have to build a map from each card to the resource identifier. This is, unfortunately, one area in which the Android resources architecture doesn't shine.)
If you want to use SQLite, it has BLOB fields in which you could store the images themselves, or int fields in which you could store image resource identifiers. Take a look at the searchable dictionary sample project for how to build an SQLite data base from resource data.
Sorry but this really is a 'it depends' kind of topic.
Unless you're storing a large number of rows of data (around the order of 10 000) then an XML file would be your best bet. In a Train Timetable app I recently wrote we went with a XML SAX parser loading a 14 000 record database to memory and it took no more than 2 seconds on an HTC Hero, so even for large databases its pretty fast.
The SQLite option is preferable only if you want to make use of relationships that come with a database structure. It is better at handling large numbers of rows but terrible at handling images.
Since you're flash cards are not relational I would recommend an xml file, using the xmlSax parser, and a folder of images within your assets folder. You could even run the images through pngCrunch to save some space.
XML is very flexible, below is an example of what your xml file could look like. Check out http://www.w3schools.com/schema/ for more information on writing an xml schema.
<?xml version="1.0" encoding="UTF-8"?>
<cards>
<card title="card 1" topic="atopic" image="image file name">
<front>Lots of text</front>
<back>Lots of text</back>
</card>
<card ..>
..
</card>
</cards>

Best way to store application images taken via camera

I'm just looking for some insight into what would be the best way for me to store images as part of my app.
I have an activity that represents a 'Job' which has a couple of edittext's and underneath was planning on using the Gallery component to show images relevant to this job.
The job data is stored in a database (on the sdcard) so was also thinking of creating a table to store 'JobImages' and having each image stored as a byte array.
But I'm not sure if it would be better to store the images directly on sdcard under a folder structure specific to my application and the job. E.g. using the job ID number as a folder name.
Depending on which method I use will greatly determine the code that goes into an 'adapter' that allows me to bind to the gallery component so before I begin I was wondering if anyone has had the same design problem and what option they chose.
Thanks,
Dave
Regardless of what storage method you choose, don't let that stop you from writing the code that will use it. Write a class that abstracts this from your app and just gives you images, how/where it retrieves images from, doesn't matter, this will also help you in the future if you decide to change your storage method, you will only have to change this class, not the whole app.
Back to the original question, it depends how you'll be using the images, if you already have a db and need to associate the images with other records or add additional properties (i.e. a database of animals in a shelter with their pictures and other attributes), makes sense to store in a db. If all you care about are pictures that don't have any need to be organized (i.e. the built in Gallery), then store in a folder.
Here's a link on how to store in DB: http://www.helloandroid.com/tutorials/store-imagesfiles-database

Categories

Resources