Send data from XAMPP(MYSQL) to android - android

I wanted a background service that listens for data from XAMPP server. I don't want the app to make HTTP requests to check data in the server periodically, instead i want to have an event in the app that gets invoked along the data from the server. This question may seem vague but can anyone suggest me from where to start?? I will be very thankful.

You can use Node.js with express and socket.io, its easy to install and for usage. But also you can use online socket services. And for MySQL querys you can use Sequelize.

Related

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!

How to connect Android App connecting to a web service

I created a small app and with this app I want to send the data (over wifi or bluetooth) to a PC/server.
I am thinking of creating a webservice that will run on the PC and will be listening constantly to any incoming client requests.
Once it receives request from client, the data transfer takes place.And after the webservice receives the data it should automatically open an application/GUI window showing the data received.
My question is Can I create a webservice using TCP/IP in JAVA and have it constantly run in background and listening to client request?
Also how do I start a GUI as soon as the webservice detects a client request and receives the data?
Use SQL Server to manage the data on your desktop and create a web-service in .NET on Visual Studio.
Then connect to the web-service in your application and set/get data from the DB, using web-services.
Links which might be useful :
How to make a web-service in .NET (does not include the implementation in Android) : http://srikanthtechnologies.com/blog/dotnet/wsdaljava.aspx
How to connect your service with Android :
http://seesharpgears.blogspot.in/2010/11/basic-ksoap-android-tutorial.html
http://www.codeproject.com/Articles/304302/Calling-Asp-Net-Webservice-ASMX-From-an-Android-Ap
http://adrianandroid.blogspot.in/2012/05/access-c-net-web-service-in.html
the best way is to create a web service and connect your application to the web service, you can use the tool http://www.wsdl2code.com that create all the needed code for connecting and parsing the data :)
I recommend to use WS on the server-side and you can use Ksoap android library on the client-side. Create a background thread which updates the UI with the new data with. Use AsyncTask, Loader or Handler which is fit for your solution. (Read the official reference for more info).
you can easily achieve this by creating an end-points/routes using node.js or php then host it on the cloud. I think I like firebase for hosting for now, u might wonna try that it really cool. after creating those endpoint which will be connected to ur database then u use http get or post request depending on what u want from ur database in ur mobile app.
if u are creating for android use Retrofit for http connection.

Best strategy to handle broken network connections?

i want to keep my app in sync with the Server. The communication between client (android app) and server is handled through JSON Objects / HTTP. What is the best strategy if the connection is not available anymore? It is important that the user can continue his work with the app. Does there even exist frameworks for such sync-problems?
i thought about a queue of transactions?! Any reccomendations or experiences?
Thanks
For fetching... I once wrote a caching URL manager that would load read the JSON from reply from the server and write it to the SD Card. When if the user did another request for the same URL a short time later, the URL manager would simply return the cached json from the filesystem as the JSON reply. This made the communication code somewhat transparent, in that I was always dealing with JSON replies, whether or not they were cached or real time.
For sending information to the server, you could write all information to the database, and use a background service that pushes the data to the server. That way the UI will always succeed in writing the information and your sync service would push data if there was a network connection. Using a Service you can simply pass the data in the Service intent and it can worry about the writing to db and syncing, etc.
http://developer.android.com/training/cloudsync/aesync.html
i think this is what i will use in my next project :)

Fastest Way to send Data from Android to Server?

I want to send image and text data from Android phone to a Server. i am new plz suggest me the best and easy way to do this task. Server is running a java web service and i will be getting the data from server and also sending the data to server. Thanks
As your server is already there, you will have to use protocol it can uderstand - also SOAP, REST or whatever it uses. So no choice for you.
If you are deigning client-server interacton with android application, you may consider network socket communuication which has less overhead as webservices.

multithreading in android

I have an app in android,a kind of client-server in which the client has stored some gps data in Sqlite database and once connected with server it delivers it that data which at its turn stores it in it's own database for future manipulation!
Now the problem is that I have to create a server that accepts multiple clients and I cannot find a decent example in this way.I'm not using no services in combination with it!
Both my client and server are on android!!!!
I have already did the connection between client and server,but only with one thread(I mean my server can accept only one client at this moment!)
Is this suitable?
How to implement simple threading with a fixed number of worker threads
Thank u in advance!
If server is Microsoft based, .net web service can be used that can be accessible from multiple Android clients and work with database.
Your server is not on the Android device I guess, so I don't think the question is android related.
Check out this example of multithreaded server in Java and this one as well.
To communicate with database, see the Java JDBC tutorial.
Those examples are in Java, because that's what I am used to, but any other language will fit as well.
A simple POST request from the client to the server should be good enough. Encode the data in a suitable format (JSON/XML) and send it as a POST HTTP request.
I don't understand why you want to write your own server. I would just use a PHP/Python script running with Apache to receive the POST request and store the data in a database (MySQL, PostGre).
On your Android device, you should put all your code in an AsyncTask. Android uses the standard Apache libraries to make the HTTP request.

Categories

Resources