Local android service receive data from local web page - android

I have offline web page on android tablet.
Is it possible to write android service which will get data from web page when user insert data and submit it, and when android service receive data than it has to save it in text file or db.
Everything is in offline local mode.

You should be carful when using the word Service besides android. People might get a worng idea of what you're taliking about because it has a special meaning for android.
Because a local webpage will submit a post request to a certain URL and your device is actually not the webserver you will fail with that. But you can accomplish your task with a javascript/JSON bridge to your local HTML. See this post to see how.
The idea is to use a click handler which collects the needed data and returns it to the webview by the javascript bridge instead submiting the data to a from submit URL. From java side to WebView you can respond with an JSON object.
To accomplish this you need to have fundamental knowledge about HTML and javascript and understand the use of a WebView.

Related

Phonegap : Loading content of apps dynamically

I am working on Phonegap android app which should take the content from my remote server.
After searching the things I found the 2 ways of getting the contents from remote server to phonegap App :
1. Getting the content using Ajax call to remote server by returning
the json data from remote server PHP file.
2. Getting complete HTML page from remote server using Ajax.
If i am going to implement one of the above, my app is going to send the request each and every time while loading the page which i think not a good idea.
I know very well how to implement above mentioned option in my App.
but i wanted to know which one is efficient.
How i can accomplished this?
I am also using the Jquery mobile.

Real-time communication between app and webpage

I'm trying to figure out how to have a real time data displayed on a webpage through the use of an android app.
For example, users are using android app and are scored (answering questions). My webpage will display the scores in order in real-time.
Iv come to the conclusion to use Redis, but what exactly do i need for this to function? Do i need a web socket where my web page will communicate with. This socket could be python where it accesses the database and then responds with the scores in order?
Im struggling to find out how exactly this would work as this is new to me. What exactly should i be looking for (terminology etc)?
Thanks
One approach might be:
set up a database on a server on the internet
program your app to save data to that remote database
set up a webservice
program the webservice to read data from the database and serve it as an html page
For extra credit
implement a REST style API which retrieves and serves data from the database
create an ajax webpage which uses the API to fetch and display data (so you don't have to refresh the page constantly)

Android - Ruby on Rails - MySQL

I have started working on an Android app for which we need to use MySQL as database and Ruby on Rails for server side code. We will be using SQLLite too on device(will sync both DB as and when required). I searched the web and couldn't find any relevant tutorials/examples which can serve as a base to start with.
I have gone through MySQL and ROR tutorials but still has confusion on connecting Android with ROR.
Can somebody share some relevant tutorials/code snippet which can explain the complete linkage of the technologies. I mean how to send data from Android device to MySQL and vice versa. I know the concept theoretically but not sure how and where to start with.
My sincere apologies for asking such a basic question or if I sound ambiguous but I am a beginner and need to complete this task. Thanks in Anticipation..
Here is a brief overview of what you should know to accomplish your goal. I am not going to go that far into detail, especially since I have never personally used RoR. Note that some of these parts might not relate exactly to RoR, but the general idea behind it still applies. I will leave it up to you to research and figure out how to implement each individual component.
The general flow of everything is as follows:
Android App <==> Network <==> Web Service <==> MySQL
Note the double-edged arrows since data will be flowing in both directions.
The Android App is the client, and the Web Service and MySQL database are located on your Web Server. I only included the Network part for completeness, but you shouldn't have to do anything once the data has been sent onto the network.
A brief overview of each section:
Android App:
The Android App is the client that sends and retrieves data from the Web Server. I am assuming that in your app you are going to allow the user to do some tasks which in essence becomes the data that you want to send to the server at some point.
Take for example, the user should be able to enter his name and favorite animal. Lets say that there is an actual "Submit" button that the user may click. When this "Submit" button is clicked, it should wrap up the data into a proper format to be sent across the network. Two of the most common ones are JSON and XML. Once the data has been formatted properly, you will want to send the data to the server using some type of network protocol such as HTTP. In order to send the data, you of course must have some URL as the target. Lets say the target is www.example.com/webservice.php. This target is our Web Service located on the Web Server.
Once you send the data, the server will respond with some data at which point you can do whatever you want with it. Maybe display it to the user, or stick it in an SQLite database, or even both.
The key thing to remember is that there is no magic going on. Everything I have just described will be implemented in Java code that you will write in your Android Application at some point.
Key Ideas you should research more and figure out how to implement in Java code:
JSON and XML
HTTP in Java
REST and SOAP
Here is an excellent video on possible ways to set up the structure of your Android App.
Make sure that you are doing all network operations in your Android App on a different thread. An easy to use method is an Intent Service.
Web Service:
This is often the most confusing part. A Web Service is simply some entry point for clients attempting to access the Web Server. My explanation here might different slightly when using RoR, but the same idea applies. Notice above that the target URL was www.example.com/webservice.php. The web service is literally the PHP code that exists on the Web Server, called webservice.php. In your Android App, when you send data to the target URL using HTTP, the Web Service code will be executed on the server (and also have access to the data that you sent to it). Inside of your Web Service code, you will basically be extracting the data (which is in some format like JSON), grabbing the necessary parts, and then doing something with it. In this case you will most likely be querying the database. In PHP it is easy to write code that connects and queries a MySQL database that is also running on the server. When the response of the database is retrieved by the Web Server, you can send it back to the Android App. Just as before, remember, there is no magic going on. All of these ideas are implemented by writing some code.
Main ideas to research:
Ruby on Rails web service
How to access a MySQL database using Ruby on Rails
MySQL Database:
This is where you will store the data on the Web Server. I am not going to go that in depth here because this is just going to require you doing a lot of reading up on how to set up a MySQL database on a web server. It is also important that you learn how to create the appropriate queries such as SELECT, INSERT and so forth.
Main Ideas to research:
How to setup a MySQL database on a web server
If you need any clarification, let me know!

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

How to get and show data on web, after posting data from android app

I am new to android and working on a project that will display data, that android will send on web, I have done posting from android using HTTP Client and HTTP Post, and got the response OK after posting. Now, My Question is that, how can I get it on web and display that data on web page each time new data is posted.
Did you write a program on the server side that accepts the incoming data from the Android device? That same program needs to store the data somewhere (in a file or database).
That program could simply output an HTML file containing the posted data. The browser could simply load a URL that points to that HTML file to see the data.
Or you could write a second program that resides on the server whose purpose is to read the data from the file/database and present it to the browser as an HTML document. With some client-side JavaScript, the browser could periodically query the server to see if new data has arrived.
The key insight here is web clients (Android devices and web browsers) are independent of each other; neither "knows" of the existence of the other and they can't directly talk to each other. Consequently, you need an intermediate store (files or database) to hold onto the data in order to pass it to the other client.

Categories

Resources