Transferring live data from an Android app to a Web app - android

First, I am a newbie in Android and I was wondering what would be the best way to transfer data coming from an Android app to a web app.
(The purpose of this is to make an IOT platform for monitoring the environment, and ideally, it would be better if the data on the webpage was live, but I could deal with it if it is not possible)
I am not looking for a very detailed answer, simply some tips to get me started would be appreciated.
Thanks

Try the following guidelines:
From your android application, create a service that runs in the background.
This service will run for example every 30 seconds or however often you want it to update the remote server.
If the data you are sending to the server must be input from a user, you can perhaps store that data locally while also managing stale data
Since the service is already running in the background thread, you won't have to worry about affecting the UI thread.
Now make a HTTP POST request, which will post your data in a JSON string to your server.
When you get your data in your web application, store them to your database as usual.
Once stored, you can have a mechanism to check for new data every few seconds and display it.
There are frameworks that make it very easy to have updates without browser refreshes. Regardless of the framework, you should be able to pull that off easily!
I hope this helps you get an idea!

If you already have this web app, a simple solution would be to create an android app based in a webview, which is a basic "tool" to work with webpages, allowing your android app to function like a web browser. Until then you cannot gain advantages if comparing this with your basic mobile web browser. The advantages could showup if you produce special designed pages in your web application exactely to be used only inside your android app. For example: simplified design (less, bigger, direct texts; less images, less elements; easy and fast visualization and use) which could represent less bandwidth demand, faster and more productive experience for the user when compared with a normal browser.

Related

Extending an existing Web application with Android app

I have a new project involving the build of an Android app for a website of a hiking club. The website has a login functionality after which the user can browse through available hikes, subscribe to a hike, view the other subscribers, contact the organizer etc.
The original site is based on a MySQL database with a front end of .asp pages. Most data is passed through the pages as GET parameters on the query string.
New to Android development, some things really puzzle me, even after reading several tutorials. I am thinking towards an architecture baes on REST webservices but there a several obstacles to overcome and chooses to be made.
Apart from using REST, some other options are available:
Call the original .asp pages from the app instead of building a dedicated Web service. This leaves me with much less code to write, the original business logic (queries e.a.) as well as the login system can be used (with the "remember me" functionality based on cookies). Downside is that the (X)HTML code in the response needs to be parsed to show in the app GUI, where the majority of the response code is useless ballast code. Also, it does not feel very good from an archtitectorial point of view.
Using a SOAP based webservice. I am totally unfamiliar with SOAP and it appears to be much too heavyweight for a mobile device.
Using REST services. I am leaning towards this option, and have made
some already working services using the SLIM framework. But there
are some problems. First, REST is stateless by definition and does
not seem to support sessions. But the "Remember me" option is
required for the app after login in for the first time, the user
needs not to login again unless he explicitly logs out.
But how can we achieve that?
First option is to designing some completely client-site login/logout system which saves the credentials locally until the user logs out. And sending the credentials with each request to the Web service as POST parameters, or somehow in the HTTP Authorization request header, though I am not familiar with that.
Second option is to deviate a bit from RESt principles and use a session mechanism anyway. After sending the credentials to the web service, a cookie is created and send to the client app. The dartabase cannot be extended so there is no option to save a token in the user table. Maybe the usernae/password can be encrypted and send as a cookie to the app, and decrypted at each subsequent request?
I am a bit lost in this, and look forward to serious suggestions!
I believe that from a long term perspective, it is important that you lean towards REST Interfaces. While JSoup and/or WebView approaches will definitely work, it is important to have the flexibility to redefine/design the mobile application in ways that are completely agnostic of the Server side. REST will help you there and you do not need to play catch up with the Server side, everytime they change the HTML pages, etc.
Going REST will also help in future with writing additional mobile applications and even on different platforms like iOS, if your roadmap contains that.
You can use jsoup to parse the html pages from your Android app and reorganize the information of the web page, this option will gives you ability to quickly develop an App, later you may think on add REST interfaces to your web site and populate data in json.
You can also use WebView to laod your web pages if you don't want to parse html pages.
I suggest you using REST architecture as you said. You can use a rest client library for Android as RESTDroid, take a look to the guide because there is a implementation example with special header needed for the particular web service used (Parse.com in this case).

asp.net Web Api and mobile aplications

I just want to make a TV guide for Android and later some other Mobile Platform. I want to use an RSS updates to update my application. In this specific scenario I want to use http://tvprofil.net/ 's RSS resource. I thought that I could just call site's RSS XML from my Android app, parse it, show, and thats the end of the story.
But, my cousine told me that the best way to do things is through Asp.net Web Api Service. Something to deal with REST. So, If I have to change resource, to like some iptv provider's RSS I would just change the Service and not have to deal anything with my mobile application. Other advantage, he said, is if I want to build Windows Phone application or iOS aplication that works the same way, I would have that same service to do job for me and just create UI and basic things for those apps.
The problem is that I have no idea how Asp.net web Api is used.
Can anyone give me some usefull link, or even better, write an example of this thig. I just want the RSS from http://tvprofil.net/ to go through Asp.Net Web Api Service and that I can call service and get it as XML or ... even Json... or to get anything at all to my app.
The whole thing is pretty confusing to me
If a RSS feed has enough data for your application to function then you do not need ASP.NET Web Api. The only role ASP.NET Web Api could play in this scenario is if it acted as an intermediate. E.g. your client application contacts your server application (ASP.NET Web Api) which in turn pulls the data from the actual external data source (tvprofil.net RSS).
For completeness sake, a list of pro's and con's:
Advantages of using an intermediate server
Reliability. You can cache the data of the external data source and serve that data even while the external data source is offline. Also, by caching the data you can lighten the load on the external data source to a bare minimum.
Transformability. Your intermediate server can translate the data of an external data source to another format that is more suitable for your client application. This is useful when you have many external data sources that each serve data in another format. Your intermediate server acts as a layer of abstraction for your client application.
Disadvantages of using an intermediate server
More effort. It will take more effort to develop and host an intermediate server.
Reliability. You must ensure your intermediate server is online and connected to the internet 24/7

providing a web service: what are best practices for splitting JSON data into two datasets?

I have a database and I need to present a data via HTTP using JSON web services. Currently, I'm designing JSON datasets that will be provided as web services. The data from the tables will be aggregated to suite an app needs.
If the data size is large and we will try to download that at once then it might take too much time and an app will not be responsive at start. That's bad. It's well known we should minimize the number of http requests the app will make to download the data. However if we would split the data into small chunks then during every app action step an app will performe http requests and that might be unresponsive solution too.
We are talking here about mobile app development, so internet will be exposed over cellular ISP or wifi, so the speed might be quite slow. I understand the split process depends on app workflow process and etc., just curious are there any general guidelines? For example: if JSON data is larger than 1MB then definitely split it into smaller chunks...
Look at how your mail read work. You probably have tens of thousands of emails in your account. The app will show the first ones then provide a button at the bottom of the list to display more items. It's a pretty good solution usually to provide a lot of data.
Also #Selvin ideas are just great. Don't use UI thread to download stuff, use a different thread. Services are pretty good for getting data asynchronously.
One of the way is to create a service which gets started when there is network. All downloaded data can be cached in sqlite and use a content provider to get the data. But it depends on your app.
Sometimes it depends on your UI Screen. For eg. You can create a Listview with load more. On click of it load extra data.
Other way is to create API such as which gives only updates based on timestamp. But its all depends on the app. Just sharing my ideas. Might not be perfect. Others can surely give a better one.

Android client/server application?

I am supervising a project done by two students that involves retrieving information from a server and displaying it on an android phone. The students have never learnt networking, sql or java before (although they do know how to program) and are only now learning how to setup socketed connections between the phone and a sample server app that i gave them.
They will need to setup a simple sql database on the server on the campus network and be able to communicate with it and only pull information from the database and display it on the phone.
My current plan is that they will receive xml objects generated on the server side sent as a stream through the socket connection. They will then be able to generate a DOM using javax.xml classes and display it as they see fit on the phone itself.
Is this a valid method? What kind of problems can they expect to experience by following this technique? Is there another/better/correct way to do this (without using php or webservices)? The system will be for multiple users so will there be any significant performance issue with the proposed method?
Note 1: The phone never sends any request other than a single multicharacter identifier. The server interprets this identifier and returns information from preprogrammed queries and places it into an xml format.
Webservices sound like the correct approach for this, since you would not want to directly allow communication to the database over the internet.
The book "Unlocking Android" from Manning Publications, ISBN 978-1-933988-67-2 has a Chapter (6) dedicated to "Networking and web services".
Ah and then there is the one and only very nice video from a presentation regarding Android and RESTful webservices from the Google IO.
Couchbase, although from the NoSQL movement have a nice summary as well.
You could use JSON instead of XML, could be easier to parse and work with (feels more lightweight to me at least).
Sorry, forgot the answer for your search of problems:
Activity freezing upon freezing requests: Use additional threads for your requests
How to generally handle high latency
Handle offline behaviour

How to save/load data Online(Store data with AJAX and JSON) and Offline (locally)

I need help figuring out the best, cross-browser compatible way to "SAVE" user input and STORE them locally(offline mod) AND on a server(online). Program will be used by Android and iOS.
I want to know the best way to track user progress while the device is online OR offline.
Hello I have been researching AJAX, JSON, XMLHttpRequest, REST, Java, and HTML5 (specifically, localStorage).
The scenario: (Read a book online/offline, save page progress)
A user logs in to a Web Service and the Web Service allows the user to download an "html webpage book" (view with HTML5 browser).
After every page turn, a REST API uses a GET request to post the Progress data to a Web Server. Simultaneously, a JSON string is created and saved in a file on the server. (let's say "ProgressData.txt")
In the background, a separate "copy" of ProgressData.txt is saved LOCALLY on the mobile device. The user then leaves the internet connection and continues to read the HTML Book.
When the user regains connectivity, the ProgressData.txt is uploaded to the server using a REST API where it will update the old server file with the NEW .txt file with all of the user ProgressData.
Possible solutions:
HTML5 localStorage solution looks good. jQuery even simplifies it:
http://plugins.jquery.com/project/html5Storage
Straight Javascript looks good for Server-Side storage, however it doesn't have access to a mobile device's physical hard-drive, thus preventing any kind of offline saving.
Java applets look possible. Plus not sure how Java runs with Android/iOS.
I don't want to have to run a localhost(PHP/Apache/Python) from a mobiledevice every time the user goes offline, however that may be where the solution lies. I did stumble on this powerful tool: http://couchdb.apache.org/
Question:
I need to know the best way to track user progress while the device is online OR offline. What is the best way to do this?
I stumbled across store.js the other day which might help solve the cross browser local storage. It was from this article about local storage.
I think your best option for tracking online/offline is to ping the server via an AJAX call when the page is turned. Always try and update the server on a page turn, but if it fails, handle the failure and store the progress locally. Each page turn will either amend the locally stored progress file or if connection is restored then simply update the server with the progress.
The issue I am thinking might occur is if a book is finished offline then there are no more clicks that would trigger the syncing, regardless of a restored connection. You may want to think about a manual sync link/button at the end of a book. Or maybe have a manual sync available at all times anyway? Give some control to the users and describe the whole offline/online reading scenario. You might find that it is easier to just let the users do the work… if they don't sync then it's their problem!
Here are 2 screencasts what will help you with your problem.
They are in Ruby on Rails but maybe you can get the idea. It is using the html5 cache manifest.
Hope it will help you!
http://railscasts.com/episodes/247-offline-apps-part-1
http://railscasts.com/episodes/248-offline-apps-part-2
some more resources (sorry i dont have experiences myself with html5 cache manifest)
http://diveintohtml5.ep.io/offline.html
http://developer.apple.com/library/safari/#documentation/iPhone/Conceptual/SafariJSDatabaseGuide/OfflineApplicationCache/OfflineApplicationCache.html
I'd suggest just using a cookie to store the current state. That way it is automatically sent to your server with every user request (so no need to build out a custom server-side API for receiving the state after a lost connection, and no need to have any custom client-side code for sending the data to the server), and still updateable even if the user has lost Internet connectivity. Also it doesn't rely on HTML5 features, so you don't need to restrict people to HTML5-capable browsers.
In any case, the best way to handle storing the current state would be to have a simple onclick handler on your "next page" link (or button, or whatever it is) that calls a function and sets the cookie value to whatever the current position is. Note that because the state is always available client-side, and sent to the server on every request, there is no need to maintain any explicit copy of the state server-side, unless you want to be able to remember the user's place even when they manually delete their cookies (which is overkill in my opinion).
You may want to look at the W3C Example Code for setting/getting cookie values in JavaScript.
Also, here's a website that demonstrates functionality similar to what you want to build. It uses cookies to keep track of a user's place when reading various webcomics. Pretty much the same as what it sounds like you want, except with comics instead of books.
It would be wise to track the progress in both a server side database and in the client's local storage if a constant internet connection is not necessary.
Evercookie is a controversial javascript api that aims to provide local storage using any means available including standard cookies, Flash shared object, Silverlight, browser history and HTML 5 storage. Data should persist when the user is offline and when the connection is restored, sync the cookie and database with whichever data has greater page number for the given book. Droid has Flash and the Flash shared object data is a "cookie" available to both desktop and web-based apps.
With great power comes great responsibility:
http://samy.pl/evercookie/

Categories

Resources