How to cache web content for offline mode? - android

I'm developing a part of an app where application is supposed to read product-images and prices from online storage (website, which is to be built for this purpose only), make local storage of product-images and prices so that it could show the product-images and prices when it is offline. there will be a button; once it is pressed, its job is to synchronize the local cache. How could I implement this ? Any help would be highly appreciated.
Thanks in advance.

You can cache the bitmaps from a remote service using a Disk Cache, there is more information about how to do this on the Google developer site http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html
This will allow you to store the images and display immediately if there is no connection, or you want to load the images whilst loading the remote images.
Depending on what text you need to store you can associate the text with the images in the cache or alternatively set up an ArrayList with the data and store to disk. Some more details here Best Way to Cache Data in Android
Also there are tools around to ensure you are making the most of your network connections, such as the AT&T ARO tool, running this will help you to optimize your app by reducing your network calls to a minimum. See http://developer.att.com/aro

Related

Firebase Storage Offline Capability

So I want to find the way to load a file(.txt and .html) in the app from Firebase Storage in offline mode except for the first time. This means a user will load the data for the first time in online mode and can access that data another time with offline mode. So is there any method to do it?
This means a user will load the data for the first time in online mode and can access that data another time with offline mode. So is there any method to do it?
For sure, there is. There is a library called Glide for Android, that can help you achieve what you want:
Glide is a fast and efficient open-source media management and image loading framework for Android that wraps media decoding, memory and disk caching, and resource pooling into a simple and easy-to-use interface.
This means that you can load an image once and then read it from the cache.

Android: Retrieve images from Server

I am building an android application which requires displaying images as a flip-view which will be retrieved from server. I have considered two approaches
Retrieving images from server URL and then displaying OR
Storing the image in db at server(MySQL) and then retrieving it from sq-lite on android application
My question is, which approach will be better considering everything (performance, etc.)?
Any other better approach is also welcome :)
This depends upon your Application and products you are going to display using Images, If they are not updated frequently then it would be better to use caching for faster user experience but if data is regulatory updated and previous data is keep getting filtered then always load using network.
Another approach you can just store latest 10-20 entries in your Database and as soon as you opens the application he can see some data and new data gets downloaded, this approach keeps users engage don't leave them your app just because every time they see loading.
For Image caching purposes there various good libraries avaible which are stable solutions for multiple images downloading as well as caching purposes E.g.
UniversalImageLoader, picasso, Volley
A good approach could be store locally images locally on demand, and keep it on cache, if the image changes on future you can invalidate your cache and download a new image.
I have used in a project a library that helps me a lot with to download the image in background, allows you also load image from cache automatically if stored previously or invalidate the cache. The library is android-query and here is an example of how you could use it.
You store images locally and load then to your app from local storage (This happens in a background thread)
You update the local storage by fetching the images in background, when needed, and then trigger the load from local storage (This also happens in a background thread)
This way you won get ANR's (application not responding) because of slow or missing internet connection, and you will be able to show images without connection at all.

How to show images in offline tablet application

I'm looking for a way to create offline order entry application for Android and Apple tablets.
Application should download product list with images.
It should allow to show large product image and allow to enter ordered quantities for products.
This order entry must work also if there is no internet connection.
If internet becomes available, entered order should submitted to server.
I looked into offline Web application sample in
http://diveintohtml5.info/offline.html
and searched sourceforge and codeplex for reference applications but haven't found any.
Most difficult seems to be showing offline images. In html5 application I found two possibilities:
Store images in Indexeddb (or in other way) and use javascript to show images
in tablet browser in offline mode.
Where to find sample for this? To to convert database data to image which is displayed in tablet ?
Create manifest containing all image urls dynamically. Tablet browser probably then loads images into offline cache and allows to show them in offline mode.
Where to find framework or sample application which can be used as starting point ?
Should I use html5 + Indexeddb + jQuery + jQuery UI or is there better way ?
Server is Linux server running C# Mono ASP.NET MVC4 application which can provide data for this planned tablet offline application and receives orders from it. I can create WebAPI controller for application.
You need to persist the images in your application and control the references using a database (search for core data for iOS and greendao for Android). Anyway you will need a mechanism to download those images from server when internet connection is available to store that.
About the orders, you can store the order locally in your database and when internet is available you sync those informations with the server, that mechanism can be called whenever you want, you need to define how will be user experience.
My suggestion: Try to break your problem in small problems and try to resolve them. Your question looks more like a general architecture question.
Here is the topics that can help you to develop these apps:
Android:
Database: greendao:
http://greendao-orm.com/
Webservice/Persistence: https://github.com/koush/ion
iOS:
Database: Core Data: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html
Webservice/Persistence: https://github.com/AFNetworking/AFNetworking
I hope this help you to start.

Android Storing RSS feed parsed data in a database for offline use

I am parsing a Rss feed using sax parser in android. I am able to display the data online when net is connected but i also want it to work for offline use and update it when it gets connected again to internet / wifi. I have no clue how to go about it.
What should be my best approach now ? should i construct Sql database ? considering i have images as well.
Or there is any other simpler way. I would prefer simpler way.
I need some further suggestion on the Sql database approach here, First : My rss feeds gives image url links which i diplay using bitmap and insutstream at runtime but now for offline purpose i need to save complete images like whatsapp does right ? is this right ? if yes how to save complete images in database ? And last i want to save the complete database on sd card not in internal memory , storing data on sd card will work fine or it will create problem ? because whatsapp stores quite a data in internal memory !! if storing on sd card is not a problem how do i store complete data on sd card ?
This depends on how long you want the data to persist. Ask yourself:
Should this data be available to the users after rebooting the phone, or after force closing the app? Should it be available regardless of the last time I had connectivity, as up to date as possible given that?
In that case, then yes - you should use a database. Android has a number of built in helper classes for sqlite databases.
http://developer.android.com/training/basics/data-storage/databases.html
Which should get you started.
The images are pretty straight forward as you'll just stash a reference to the image(s) in the db. You would of course write these images to disk as well (on the sd card or some other place...) See:
Save bitmap to location
Your other options, afaik are:
1) SharedPreferences (not really suited to this).
2) Serializing your data and writing out/reading in from some file.
If you're still looking for more information on Database concepts and Android, here is a very good tutorial on the topic:
http://www.vogella.com/articles/AndroidSQLite/article.html
You can use droidQuery to download the RSS Feed and cache it. Working off of this gist, which expects you to use the android-rss library, you can add the following cache flags to your AjaxOptions object:
.cache(true).cacheTimeout(AjaxCache.TIMEOUT_NEVER)
This will make it so the response is cached until you explicitly call:
AjaxCache.sharedCache().clearCache();
Which you can do after the network is connected (for help on this, check out NetWatcher).
Note that using this cacheing mechanism allows a very simple solution that will only store as long as the app process is live. If you want to save across sessions - so that if the user opens the app later and is not online, you will want to use something more complex and long-lasting, such as SharedPreferences or SQLite. A good list of options can be found here.

How to build a simple offline form submission app?

I'm a Webdev beginner, have been learning some Python/PHP/Javascript and want to help a friend of mine with a project.
She's conducting a large scale survey of old houses/windows, and fills in forms (similar to Google Forms). However, she doesnt always have 3G coverage on her phone, so she wants some way of uploading the data when she gets online, and she wants to be able to upload photos and attach these to the forms.
I've found a javascript-library which makes use of html5 localstorage, but I havent understood if localstorage also accepts file uploads? Also, when you have submitted one form you would need internet access to open up the form again to submit another form.
Are there libraries or projects around that would help me with some of this, so I dont have to reinvent the wheel?
This is going to be very difficult to do with a web app. Your going to have to rely on something like AJAX to send the data and if it times out store in local storage and keep retrying every few minutes, because a web app has no access to anything like checking the wifi status etc.
Also that there is a limit to the size you can use in html5 local storage:
What is the max size of localStorage values?
, this is not going to work if you want to hold onto photos.
This would require a native or minimum a hybrid app (like phonegap) to store the data on the actual device in a file or SQLite database. This way you can store what you like, have access to the status of the internet connection and even have prompts to appear on the screen (when the app is in the background) to remind her that there are still some that need to be uploaded.
It will be much more reliable and stable this way
You can create an app which stores the data (form) in the Local DB (ie SQLite) of the App.
Once she is online (mostly wifi) she can start uploading the data.

Categories

Resources