Project Description: I have to make an application in android which gets the Latitude and Longitude from GPS and forward their location with identification to server. On the server end there should be web page which continuously receives the messages from the Android application and shows the location on Google maps.
Suppose there are 10 Android devices at different places in which our application is running. On the Server end we have to show 10 markers on Google maps at the location of devices.
What I have Done: I have made an application in android which gets Lat and Long from GPS. I'm familiar with socket programming on android. I've implemented the web page on the server end which has Google maps and shows the markers.
Confusion:
How can I make a server?
How can I transfer data from Android to server and what application required at server end which receive the data from Android. Is any desktop or console application needed which bind it-self at particular port of server, or web page is enough for me to achieve this target.
What protocol do I have to use? UDP, TCP/IP, or use the HTTP or HTTPS steam directly?
I just need some direction about my problem because I have never worked in Android and Client Server Communication. If you think this question is vague then please recommend a book about networking or any which you think is suitable for this type of problem.
A common setting can be like this:
Have following things:
A file (PHP) at server's end, whose sole purpose is to inject the data (lat,lng) received from android devices into a MySql database
A file (PHP) at server's end whose sole purpose is to fetch you the data (lat,lng) from the MySql databse. This file should receive a timestamp as its argument and return all the values of lat,lng who have been saved after that timestamp (For this, your database must store timestamp)
A file (HTML+JS) which just handles the map thing, has an AJAX call implemented which polls the second file at regular intervals with a timestamp value to get new lat,lng values. and when it gets the values, it plots them on the map
On the Android devices, make your app in a way that it keeps sending its location to the first PHP file at a particular time interval.
This way, you get what you wanted.
On the other note, If we talk about client-server architecture, a client sends the request and gets the response. that's it. for this, client accesses a server side script to get those responses. same way, your android app accesses a particular server side script and gets the response. That's it.
In the case when you want to implement server initiated communication to android, you'll have to use push mechanism, like Cloud to Device Messaging (C2DM)
Cheers.
Afaik...
First you need to get the data of GPS by using Location baser services provided in Android SDK(See Location MAnager, Location Listener etc etc...)
Confusion:- The confusion is that
How can I make a server.
Ans: Cant help you with this because i m not expert at configuring servers
How to transfer data from Android to server and what application required at server end which receive the data from Android. Is any desktop or console application needed which bind it-self at particular port of server, or web page is enough for me to achieve this target.
Ans: You can transfer the data that consists of the Latitude and Longitude using a webservice that recieves the data using get or post methods and then dumps it into your database every time the OnLocationChanged method is called on Location Listener. Preferably u can configure a mysql database in your server and then use it for your data storage. The web page you need to design in such a way that it frequently gets the location related data from the database and then display markers accordingly.
What protocol which I have to use UDP or TCP/IP, or use directly the HTTP or HTTPS steam?
Ans: If you are aware of php then u can use REST services or if you are .Net kind of guy you can use a SOAP webservice that uses simple http post methods to update data to the server.
Hope this helps.
Related
I want to connect my Android App to the back-end. The aim of the project is to filter spam messages. So the app receives SMSs and then should forward it to server for spam filtering which uses machine learning. Now, the thing is we have a python program for machine learning but I don't know how to connect these two things - the Android app and the python program. Need guidance on how the app can send data(sms) and receive response(whether spam of not) to and from the server-side.
A common approach is to connect your client with a web backend that offers a web API (might be a REST API).
Here is a short overview over this topic: https://www.webiotic.com/api-for-mobile-apps/
What you need is a web server which can receive web calls and send back information. A web server in this sense is just a program which listens to incoming HTTP calls.
In your case, this might look like this:
The server is programmed to listen to web calls with the HTTP method POST on the route /checkMessage
It expects the message data in a certain format
For example in JSON with this content: {"message":"Your actual SMS message"}
the server checks its database or triggers a ML job
server returns a result in a specified format. For example this JSON: {"isSpam":true}
Your app then needs to send a POST call to https://www.[YOUR_URL]/checkMessage with the specified data and wait for a response
There are libraries for android which help you with that like Retrofit or OKHttp
As for which technology to use: It's up to you. You can create a web backend in pretty much every language. In your case, you should check out which Python libraries are available to listen to HTTP connections.
Keep in mind that if your app can publicly access your backend, then everybody else can as well. You will want to add some kind of authentication as well.
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 am working on a Point of Sale application that needs to be very good syncing mechanism. We have Magento Database.The android device have SQLite local Db. Now we need to sync in the following way:
Local ------Sync To---------------> Server (Up Sync)
Server------Sync To---------------> Locals (Down Sync)
There are 2 things:
1) write-to (How to take care??)
For every change that i do on local ,it will directly sync my local to server
2) write-back (How to take care???)
Whenever there is a change in server, we need to sync all our locals with server.
So, the task is: to identify a server update
And sync our locals.
Like there are 4 devices are running in a store and we have added one new customer through one device. Now i want that the three other devices local db also updated with the information about that customer and server also updated.
I heard about the background threads and run threads after a time interval. But what is the best way to do that which don't affect the application. Also the all Big Retail stores uses the syncing process. what they used for that ?
Any help is appreciated.
It fully depends on you database structure...
you have DATABASE in LOCAL (device) and on SERVER
NOW
You need to have TIMESTAMP fieLd added to the TABLES which actually you want to keep in SYNC.
When ever you will make any changes on server the TIMESTAMP will be updated there and same will be the case for the local database also what you have to do is now.
Run a service in the background which will keep on comparing the TIMESTAMPS of LOCAL with that of SERVER.
Now you have to put condition that if TIMESTAMP of SERVER is newer to that of LOCAL then bring changes from SERVER to LOCAL,
and vice versa will be the condition to take changes from LOCAL to SERVER.
Further you have to decide how frequently you want to run this SERVICE.
ALTERNATIVELY:
You can make the table there on SERVER which will store LAST_SYNCHED date for particular device
Whenever you will login in you device (or any other particular event on which you want it to perform this) the server will check-
when this device was LAST_SYNCHED
then it will compare it to TODAYS DATE
and will check what upadets actualy happened between these dates and
will send the changes to the LOCAL (device)
and vice versa for LOCAL (device) to SERVER
you have to play with TIMESTAMPS rest you can have your own logic how to structure the database.
I told you what I have have observed, when I have been a part of such similar project
EDIT
The above Process defines how to sync the devices with server I mean the strategy..
If you want your devices to get notified from server when to sync instead of hitting the WEB-SERVICE recurrently ..
You can make use of PUSH NOtification, GCM is one of them that send push notification to devices, you can integrate it to your project
For syncing you need to handle following two situations.
How and when to receive server updates
How to identify local non-synced data
How and when to receive server updates:
For receiving updates, we can use GCM (Google Cloud Messaging). If any updates made in server, server sends a push message to all devices. Devices will receive that push and based on the message, devices will download the data from server. (I think this is better approach than continuous hitting service for some particular intervals like polling)
For receiving only updated data from server, server maintains modified_timestamp column for all tables. First time devices will send empty timestamp, so that server sends all data to the device with server timestamp. Device receives the new data and updates local db and saves the latest server timestamp. For next time to get server updates, device will send stored server timestamp then server will send only modified data after that timestamp only. For each response server sends server timestamp, devices needs to store that timestamp and needs to use while calling service.
How to identify local non-synced data:
For sending local updates, local db needs to maintain one 'isSynced' column in tables. If any row modified in local isSynced will be false, after successful syncing local data to server isSynced will be true. so that we can handle local data up to date with server.
Updated:
You can find more information on this developer link
Have you considered using commercial solution?
http://www.mobeelizer.com/ seems like what you want to achieve. There are probably many other.
Note: no affiliation with that company.
I would say that the problem statement is incomplete. In above described setup what is missing is what actually you are going to synchronise.
Usual case in POS is that there exist few indices (id,value,...) tables that shall be distributed from central server to the client devices. In most cases it is price list, stock list, etc. Those tables should rarely be modified on client devices (actually could but then has to be redistributed from central server and acknowledged by client devices).
The other direction tend to be also pretty straightforward on client device you generate bills or invoices. These are again local stuff that shall be propagated towards server. Thus you actually store them locally and at sync point dispatch them to the server. Later on you might receive your own items back from server as an acknowledge.
EDIT: to detect changes, on-write timestamps as mentioned above is a must.
So far above described is the data flow.
Next you have to move into solution domain and implement these rules. There is couple of sync approaches (i.e.SyncML). On the other hand keeping it simple rulez. Thus the main concern should be some kind of locking and queueing that makes the thing robust.
It could also use the agent based client, in such case each device has it own agent (could be replica of last known state of the device db) but I would consider this as an advanced feature that might come in future release:-)
I am also working on the sales app in which i have to my local goals to server and server goals to my local goals
My proceder is that when ever my app is started i get the latest data from my server of my all my member and update my local data base with this data and when ever i change data in my local data base also update on sever side
also i used a sync button which will fetch latest data from the server if my team member changes its goal or profile
IF you want updated data on all the devices, why don't you use remote database only, why are you introducing local database for this.
For your case i will suggest you to work with only remote database directly so the things can be done real time.
I want to create client-server GPS tracking application that clients send location data to server and server saves them on database and show clients location fleet location for site users and give report for them.
In this application i don't know which method i can use.Client applications is android apps and server application is web based application.
Methods for send data from clients to server:
1)Consume web service in clients and send data to server by means of web service
2)Use MQTT in client application and send data with MQTT
in 1st method because data is little when a web service want to send that data to server use XML and this can increase data sizes! and web server for obtain location data first need to decompress them and get location data from web service package that this can use server resources!.But method 2st send location data direct to server but hard to implement and encoding!
which of the methods you offer for me to use in this application?
another concern is if i want to scale this application for other client side platforms like iphone which of above methods is optimum
Have you thought on using a REST service instead ?
So your tracking device will basically just call a REST url and POST data to it.
No overload of data size or compression.
Same REST service can be consumed by an Android or iPhone app.
My project is create application on android. It can get a location(latitude,longitude) via GPS.After that I want to send a location to a server or web server to collect for calculate a distance which are draw on my own map(may be make from Flash) on a website.
I knows an android have apache, but I don't really know in detail about server, web server, apache.So, I want to know how to send a location from my application to server.
Anyone can help me or suggest me?
Appreciate,
Daisy
PS. I'm a newbie.
If you're writing both the Android part of the application and the server part, then you can decide how to transmit the data. You could go with some simple JSON like:
{"lat":12.34,"lng":56.78}
No reason to come up with anything more complicated than that if you don't have to.
I don't think its necessary to have apache server on server side,
AFAIK> android can ping to any web service on any web server. I can ping an asp web service that can be hosted on IIS.< AFAIK
You can ask the developer of that site to develop web service (api url) that can accept latitude and longitude as parameter (or search the api if they have one (a la google maps case)) and you only have to care about calling that web service.