Most efficient way to store text and media in android development - android

I have an application that I want to develop. The android application is more or less like a book that will allow the users to select a chapter and it will display the whole text in that chapter and a media file for the chapter. Where do you think I can store the text and the media. Should I use json format or sqlite database or I should store both text and media in a folder and access it there. Am really confused because I still want to be able to perform some query on the text search for the text in my application.

You can use binary files, where you load the data sequencial.
Or you use zip-files, in which format many programs store data. Eg .svgz is a zipped version of .svg used by Inkscape, .odf is an open source format used by eg. OpenOffice or LibreOffice (the specification says it could be either a XML- or ZIP-structure.) You can store the text in a file, where in the text it references to other files like images in the zip, like a html-file references to other files on the server in the directory. This can be a json-file or an xml-document or a binary-serialization of an object-structure. There are many zip-libraries out there,. It is a big security risk, if you do not check in the file for references to other files outside the zip, like '../../Documents/myPasswords.txt' (when you are on Windows for example and you use the %temp% directory, this may reference to 'C:/Users/BOB/Documents/myPasswords.txt' when the directory where you unpack to is '%temp%/randomName/'), when unpacking the data to a temporary directory and load a file (however different operating systems treat this differently, Android is more secure than Windows, but the app can crash if you do not check...).
But if you do not care about filesize and if you store the data directly within the app (and not download them from the internet), you just include it in your data-folders.

Related

How to add markdown's image folder in a sqlite database?

I'm writing an Android application that consists in a collection of university notes taken in markdown.
I would like to save these notes into an sqlite database, in such a way that, when I will write new notes or modify old ones, I'd need simply to upload the new files in the database and update the db version in the app.
I'm able to add a table in my database whose tuples contain the plain markdown I wrote.
Though, I would like to be able to load in the database the "image" folder in which I have put the images I refer to in the markdown files.
----------------------------------------------------- EDIT 1 ---------------------------------------------------------------
In case I've not been clear, let me give you some context:
I have a folder in my PC in which I've put many markdown files.
In the same folder I've created a folder called "imgs", and whenever I want to add an image in any of the markdown files I write something like this within the markdown file:
<img src="imgs/image_name.jpg">.
Let me show you what it looks like:
the folder where I've put all my markdown files and the image folder
So, suppose I've just downloaded the picture of a cat and called such picture cat.jpg.
Suppose I want to add this picture in the markdown file called 1_introduction.md.
I would simply put the image in the folder imgs and write in 1_introduction.md the following:<img src="imgs/cat.jpg">
What I've explained above is simply what I've always done on my PC for the last couple of years: I wrote plain markdown files and saved images into a folder (as probably 99% of people do when dealing with markdown files!)
NOW I want to store these markdown files (and obviously the imgs folder as well) into the database of an Android application.
MOREOVER I want to be able to modify the content of these markdown files (locally, in my PC. I don't want users to be able to modify these files) and give the possibility to the users of the Android app to retrieve the updated content simply by updating the app (NOT reinstalling it).
my final questions are:
is there any approach suggested by the Android community to handle this scenario? In case, what is it?
In case there is not, is it possible to save the imgs folder in the database, along with the markdown files? and, if it's possible, how should I modify the html tags <img src="imgs/image_name.jpg"> in order for it to work?
The other alternative would be to save the folder that contains both the markdown files and the imgs folder in the folder assets, but wouldn't the user need to redownload the app in order to witness the changes I'd make?
Thank you in advance!

understanding Android application cache files

I understand that the cache is data that is temporarily stored from a specific app. Opening /data/data/com.blah.blah/cache/ using a root file explorer reveals these cache files to me. I am able to open and view those that are an image, but when opening a non-image cache file - usually with a text editor - I get a bunch of Chinese looking characters... I know that basically the apps cache is only viewable by said app, but is there any way to convert file to a human readable text file?
but is there any way to convert file to a human readable text file?
Contact the developers of the app and ask them.
There are a dizzying roster of possible file formats, even among "standard" types. Any given computer program might use one of those file formats, or invent their own, or use one of those formats but encrypt the file, etc. There is no requirement that all computer files contain human-readable material. For all we know, the developers of this app are storing random numbers in these files, specifically to confuse people who try to reverse-engineer their stored data.

Downloading (paid-for) content into an Android application

I have a simple application that should handle (display, play...) data downloaded by users. I.e. when the user downloads the application (for free), it is empty, or filled just with some sample data, but then the user can download the actual content of their preference (and potentially pay for it via Android billing system). Each item is a folder with an xml file plus several sub-folders (such as audio and images). In the development phase the data are stored in the assets directory.
The payment itself is not a subject of the question at this point. I am actually interested in the following:
where can I store the downloaded data in the phone so that it would be accessible for the application but so it could not be copied manually by the user (for example to another phone). It would be ideal if I could store the downloaded data in the assets directory but I'm afraid once the apk file is generated, assets are "locked" and cannot be easily extended (or can they?) If I store them on the phone's card (or in the built-in memory), they will be accessible by other applications such as media player or galleries, too, won't they?
it would be great if I could download the package as a single single file - is it possible to upack it by an built-in method and store it as a folder with upacked (and thus readable) sub-folders and files?
when the application is downloaded, it is an apk file. Therefore it should be possible to have the sample data (i.e. downloaded with the application) at the same location as the data that will be downloaded later. How can I ensure this.
the data can be pretty large and therefore it is not an option to have all of them included in the assets folder immediate after the download and unlock it on basis of the user's actions
once the data are downloaded, they must work off-line (i.e. the user must be able to display them without internet access; thus it is not possible to check identity of the user on the server - they can simply display anything they have previously downloaded)
Example (for clarification purposes): have an application able to display recipes. It does not contain any or just a few after installation. You should be able to download recipes (one by one) from a server (each having a certain file structure stored in a seperate directory). Once they are downloaded, they become an integral part of the application and always accessible for the user even if the use the airplane mode of their phone.
Hope it makes at least some sense (I can clarify the question further if it doesn't). I've found several tutorials on how to work with data stored in assets and on how to handle data on an sd card but none concerning this particular topic.
you may store your date in your application data folder, basically it's available to your application only. if you want to prevent your data to be copied to another phone, generate a random UUID on the first run, and then use it to encrypt your data stored in the data folder. another phone will have different UUID and different encryption key, making it pointless trying to copy encrypted data. you may even use non-symmetrical encryption and send your generated (public) key to the server and have the server to encode your data and send it back in encrypted form, thus preventing your data to be exposed at all.
the assets/ folder is generally read-only, you may put your data there only during the build step.
make your file a .zip file -- these are compact and you may easily read files and folders and whatever you need using java.util.zip.ZipFile
sample data goes into assets folder, you may copy it out to the data folder on the first run.
once you download the data and save it to the device, i don't see any reason why your application won't work offline

How to provide some resource files for an android application?

I'm writing an android application, which user can download some image files from server. There image files will be stored in android mobile.
Now I want to put some of image files inside the apk file, that user can start the application quickly after installing. I found I can put them into assets directory, but the directory is read only. When user download other image files, I need to store them into another directory.
So there will be two directories to store the image files, but they are the same type.
Is there any good solution for this case?
Check out http://developer.android.com/guide/topics/data/data-storage.html#filesInternal for a listing of different places you can put data on Android.
You should put downloaded image files into one of three places, depending on your needs.
If the images are meant to be viewable by the user (e.g. downloaded photos), put them on the external storage. If they are meant to be user-interface elements or other crucial (but not user-facing) images, put them on internal storage. If they are meant to be cached for quick access but downloaded if necessary (e.g. temporary images like those found on a website), put them in the internal cache directory (Context.getCacheDir()).
If you don't have a lot of assets, you can copy them to the target location when your program first runs (e.g. check for the existence of a certain file, and create that file when you are done setting up). Then you only have to check one place (unless it's the cache dir, in which case you can't guarantee that the files will stick around forever).
If you have a lot of asset files, I would use a two-stage lookup: consult your downloaded image directory first (so you can override builtin assets, for example), then consult your assets directory. This is also flexible enough to allow you to make use of multiple storage locations should you find the need.

Best way to do a separate data install on Android

I want to decouple data from code on my Android application, and I am not sure of the best way to do that.
For instance - with the Linux Mahjongg game you can add new tiles to the game by dropping a specially formatted file into a specific directory. The Mahjongg game checks that directory when it starts up.
I want to do the same thing with my Android app - I want to be able to install the app, and then have separate installs for different data files. It's the data file installs that have me hung up. I do not want to have to set up my own server and write my own download code.
You can ship the data with the installer app, then use Input/Output Streams to copy the data from the assets or raw dirs.
Check this out:
Ship an application with a database
The answer has an implementation of in/outputstream. You don't need to use a db, just copy the file to ext storage.
One important detail: if you put the file in assets, it will be shipped compressed, and the phone/tab will try to uncompress the file in its entirety in memory. One (hocky) way to avoid that is to name the file .mp3. Assets in .mp3 format are not compressed. (Hey! I said it was hocky!)
The installer app can either uninstall itself by using ACTION_DELETE in an intent (see http://android.amberfog.com/?p=98 for details) or just show a msg to the user that it's safe to delete the data app.
HTH,
llappall
by dropping a specially formatted file into a specific directory
You can do that on external storage. Create a directory, and check it when your app starts up for new files. Tell the user they have to stick the magic files in the magic directory for it to work.

Categories

Resources