I'm developing an Android application but I need some help.
I need to store about 2000 image in high resolution (1024x768 and about 2.5 MB each) and the application must work offline so i can't retrieve them from an online database or from anywhere else. These picture should be stored in the SQLite db inside the application because each one of them are related to a specific product.
I've tried to convert the picture to a Base64 string but the result is too big and the app crash. It works only if it's about 467x300 and 30 KB but it loose all its quality so this is not a good solution.
Hope you have helpful suggestions. Thank you.
The way this problem is typically solved is to not store the images in the database, but rather store a link to them in the database. If you want them to be private, store them in the private app storage location. Getting images from a database is tricky, and editing binary blobs like that can be tricky. It can cause issues in the database, which might cause things to be slower. Also, it's easier to load images from a file than from a database.
Also, you could use BLOB, which allows for storing binary data. SQLite supports that, so...
Here is what I did to handle my high resolution images:
give a unique image id to the image, stored in the database
save the image in the android storage
whenever I need a high res image, get its name from the database. use the name to look up the image from storage.
I'm happy to provide a code example, just let me know.
Related
I would like to create an app where I could save text, image and audio notes to an offline database(without internet connection) and then show them in a list-like layout. Wouldnt like to save the files to internal storage directly.
Its my first time creating mobile app so I need help in choosing the right database for such use case. Any suggestions?
I think you may be confusing some terms.
While you can put all sorts of media in a database. Sometimes it not the most practical solution. It sounds like you might be thinking of file storage, not a database.
Further more, the files have to live somewhere, if not on a external server/database, than they will have to reside locally on the device. Your app will not have a local database service running just so that it can store media files. This would be a lot of overhead and take up a lot of resources.
the first thing to know: the database in android is SQLite, So any other offline database it's just a layer for managing the SQLite database, and It only saves numeric and text data, but you can save any other type like image, audio, array...Ect by creating convertors to save it in the database.
E.g: You can save BitMap-Image type- by converting it to ByteArray-List of 0s and 1s-, then converting the ByteArray to String-Default text type-, then you can save it to the database, and when you want to select the value, just convert by the opposite (String -> ByteArray -> BitMap), So the trick here is to know how to convert between the types.
Now the answer:
the best offline-database is RoomDatabase, the fastest way to create and manage SQLite database, with Room you don't need to build an SQLite database from the scratch, it's going to build it for you, and has a great way to create converters.
but for you as a beginner, standard SQLite is more than enough, if you will see RoomDB more difficult.
I need to store images in Firebase - storage and download them to every connected devices as soon as the image is added to the storage. However, what is the efficient way to achieve this?
Should a Firebase-job-dispatcher be used for this purpose?
Or is there any listener/methods that fetches the images and sync the storage?
The Download Files on Android docs from Firebase does explain various methods to retrieve the files such as : by bytes, via URL, FirebaseUI. However from the app perspective, how do I listen for any change in the storage(insertion/deletion of an image) and thereby performing operations in Firebase? If a new image is inserted, download it, or if its deleted, remove from app memory.
Any info regarding this would be much appreciated.
I'd suggest using Firebase database and having image url properties pointing to your images. This info will get synced back to client and you can then use something like Picasso to render the image (using the url).
I want to save downloaded images from a server. I want these images to be accessible only from within the application itself. I don't want the images accessible from anywhere else, i.e. someone can just delete/modify it like if it was on the SD card or from another different application. I'm thinking it would be best if I were to use internal storage, as it is private to my app.
http://developer.android.com/guide/topics/data/data-storage.html#filesInternal
are there better options out there?
Internal storage is the best option if you want to keep your files private.
However, on most devices, internal storage is very limited and the users might uninstall your app if you use too much of it (images can be pretty big).
You should look into using the external storage to save images, and possibly encrypting them if you really want to keep them private.
As already mentioned by Raghav this would be a good option, and as said the internal storage is very limited (mostly on older devices), however if you are on a rooted device it will be possible to delete your files anyway. Take into account the limited storage, as people is also making "swap partitions" on their SD cards because internal storage is very limited.
This is is the simplest solution. The other typical solution is to store the image as a blob in the application's database. This will make it completely inaccessable outside of your application. You can do it using the method shown here:
How to store and retrieve a byte array (image data) to and from a SQLite database?
The draw back to this is the relatively small memory space you will be given for your DB (<60MB), so this only works if you have a small number of images.
I am working on a app where I would like to download images from a website and then save those images into a sqlite database. I tried already to find some good tutorials and the only thing that came close to what I would like to do, is a article by Tim Bray.
http://android-developers.blogspot.de/2010/07/multithreading-for-performance.html
The code is really nice however it does not account for saving each single image. Bitmap unfortunatley (as far as I understand) does not distinguish between each image.
I would like to ask if anybody could give me some pointers or even better has source code for such a problem.
If you want to store images into a database you can store them as a BLOB-value.
Take a look here for that part: http://www.tutorialforandroid.com/2009/10/how-to-insert-image-data-to-sqlite.html
i am making an android application that will use a database. the user won't be able to edit the database, the database will be static most of the times, but i will need to update the database frequently for future releases. It will only contain 1 table but with hundreds or even thousands data.
Which one should i use so that it will be efficient and effective memory-wise ? XML or SQLite ?
Any help will be very appreciated.
P.S. I have read Raw resources versus SQLite database but i decide to make a new question rather than replying to an old question.
Go for Sqlite always , File Processing is Costlier than Sqlite. And also Sqlite will be more secure than XML. The Thing that you are trying , I had been gone these kind of issues. There I started with File but at one point of time , FILE IO was making my app very slow because of huge data processing. to Overcome that Issues I used Sqlite. As a result , My app became 10 times faster !
If you plan to work with alot of data i would recommend SQLite.
It will allow you to update or alter the database when your app is released without erasing any current information from the user's phone they have in the app.(Very beneficial)
It will also be good for querying with a cursor and pulling information fast.
I would recommend this!