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.
Related
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)
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!
I have tried to create a news app that display news from some website.
Some friends helped me to write some php so that I can call the php using http request and get the JSON from the response.
Then, I can parse the JSON and display the news correctly.
However, the server is not mine.
Actually, I don't want to have server communication using php.
I want to do it just on client side.
1) I know how to parse the html and get the result using python in local machine, is there any way to implement my python code in Android, and after running the python code, it will connect to the news website and display it correctly.
2) If not, what can I do because I do not want to host a server.
This is a fairly vague question however I will answer the one specific part:
is there any way to implement my python code in Android, and after running the python code
Yes, its called Scripting Layer 4 Android which supports many languages. Specifically I found python-for-android which allows you to run python on Android devices, which you could use for your application to pull and parse html from a news website.
I am developing an android application in which i want to use JAX-WS. The idea is to pull data from a mysql database that i will set up on a server (currently a wordpress website is hosted on that server location). What i want is for my android application to pull some data out of this database that i have set up on the server machine. Will i be needed to write a web app on the server side. How to go about this? I do not properly understand what will be needed for this process and how to set it up. Please help. Is there any step by step tutorial that i can follow?
This is a great tutorial and startup:
http://www.vogella.com/articles/REST/article.html
I've been using the same setup as you want to and it works great. The tutorial only goes through the webservice and it's content, then you will have to add database connections to it
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.