Store retrieve data (.txt) from SD card - android

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.

Related

Saving array data collected by app to computer?

My app collects data which it stores in arrays, and I need to be able to access the data from outside the app. The tablet I am using has no SD card, so I'm thinking the best way to transfer data would be to save to 'external' system memory. I have found tutorials to save data on internal storage and for specific data types like pictures onto SD cards, but I can't figure out how to write an arbitrary file to an arbitrary location. Thanks.
This sounds like a perfect time to use a SQLite database. Android comes with SQLite support built in so its easy to set up. You can just create a database and store your array data there (you can even store pictures too as a byte[]). There are a number of tutorials that show how to do this. Here is 1 and 2. It should be pretty easy from there.
I'm not sure that you can write to an arbitrary place on the Android system. You could write to a file in /data/data// and then email that file to yourself.

Add and load images, videos and pdfs from a raw folder or an SDCard Android Tablet design?

Good day, I have a requirement to create a kind of book app with pdfs, images and videos worth up to 10gb and more on a tablet locally. Now there is no intention to sell it on the android market or any other store, its completely in house, so i think issue with apk size has been clarified. What am asking is, where is the best place to put all this contents so that i can readily load them up and use them accordingly?
Should i be using the raw folder and create sub-folders for each images, videos and pdfs?
Should i create folders on an sdcard(assuming there is one in place)? or
Please if you have any other solution or ideas on how to implement this, I would gladly like to hear this. Thanks for your responses in advance.
P.S by the way, since its a tablet specific app, is there any need to have a multi-pane layout fragment or ii can just use all the space. thank you
I suppose you can use a RAW folder, but it would also make the APK size huge from what I understand because all the files in the RAW folder need to be packaged with the application.
From what I've seen in the past, most applications, actually most games, that have lots of extra data will download the additional data on first launch. Basically:
The application launches
It checks whether or not you have all the additional data (Books, pdfs, images)
If not, it starts downloading that data to the SDCARD.
It may not make sense in your situation, but doing it this way gives you more finite control over how much data needs to be downloaded. If function A only requires package A of additional data, then you only need to download package A, you don't need to download everything. Or perhaps you could let the user choose what packages of additional data they want to download, which would also save bandwidth, time and resources.

Android data (text+image) storage

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.

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