how to receive data from server to android - java

I am trying to make an Android application about cars tracking using GPS.
Like this "the system is having GPS and send a data (Longitude and Latitude) to Web Server GPS, and then Web Server will send it (Latitude and Longitude) to client (android)"
My question is how the client (android) to receive packet data from server that include (longitude and latitude) to display position car in google maps (android).

You could just write a web service that returns the data you need, and poll it at regular intervals. This is the easier solution.
A better one would be to use push notifications by utilizing Google's C2DM, but it's still in beta as far as I know (which is a shame, truly...). But still, it might be good enough for your needs, check it out here.

Try to use web service which serves location of cars or use http.

Related

Push notification in local web without internet

I'm aware of GCM services for push notifications, but I have this issue.
I have a android app which will send a data to a local web server (php) that will response to another android device with the data sent, a normal push notification with GCM, I think.
But I need this to work even without internet, because it is a local web app that will work only that.
Is that even possible? Android device X send json data to web server that will send the data to other android device Y.
How can I verify that exists new data in the device Y ?
Thanks. I know its a little wierd.
Yes, it is possible. But it is not easy to develop. This is why:
Push notifications work attached to an account service. So you would have to implement an Authenticator service and then the whole push platform yourself.
I would not use GCM for what you are doing though. If it is working on a local network, you can use "polling" (request the server every now and then for updates)

How to call android method from server?

I have an android application I build which gets the current location.
I want to call this method from a server, and get the location, instead of using a timer in the application which sends the location to the server.
Is there a way to do this?
Basically you can only send a trigger to the device so that it then answers by sending the location to the server. This is based on the Google Cloud Messaging service. You will find everything you need there in detail.
Another way for you to do this is by using a TCP socket. The Android application must connect up to the server. As long as the connection is live, the server can push down a message requesting the GPS location. When the application receives the message it needs to decode it and decide what to do. It should see that it wants the GPS location and thus decides to send the GPS location back.
Although, like WarrenFaith answered, Google Cloud Messaging is another way to push down an 'event' to the application. From there the app must push the GPS location to the server.

What is the established way to request data from an android device

I currently have an small application that I have been using to learn java/android programming. Right now I have a setup were the app on one phone sends a request (via sms) to another phone running the same app. The remote phone receives the request and sends back some info. Next I would like to try this from the web. Is there an established "best" way to to this?
I was thinking I would have a web server send requests to the device via google cloud messaging and then have the device return the data directly to the web server. (Not that I really know how to do any of that just yet).
I see that there is a google cloud messaging return path (send messages from the device to the google cloud server, but it seems very new, do I need something like that? The main thing I want is to be able to ask the phone to do something when I want, not have it poll to see if there is a request, or just periodically update some status.
UPDATE:
Thanks to the answers below for confirming to me that I was on the right track.
I now have some basic functionality.
I started out using this gcm android demo code
https://code.google.com/p/gcm/source/browse/#git%2Fgcm-client%2Fsrc%2Fcom%2Fgoogle%2Fandroid%2Fgcm%2Fdemo%2Fapp%253Fstate%253Dclosed
and this ruby gem
https://github.com/spacialdb/gcm/blob/master/README.md
between the above two I was able to send a message to my phone pretty easily.
To get the round trip working, I setup a very simple rails app on heroku.
I included a modified version of the sample code in the gcm gem in a controller and then used
HttpPatch (needed for rails 4) to send a post/patch from my phone to my web app, the controller then echoes the message back to my phone.
I guess it would be nice to get the two way gcm stuff to work, but I am not sure there are any gems that handle that, and I am not qualified to handle a task like that :)
I would say it's the right call: Google Cloud Messaging for Android
From the site Android Developer:
This could be a lightweight message telling your app there is new data
to be fetched from the server (for instance, a movie uploaded by a
friend), or it could be a message containing up to 4kb of payload data
(so apps like instant messaging can consume the message directly).
In this case you don't want to fetch data from the server but you want to send them.
You can send them in different ways. I would suggest, since you are learning, to try a RESTful solution using one of the implementation of JAX-RS.
As a short and direct answer for beginner : GCM (Google Cloud Messaging) would solve your issue. However, if your app turned out to be something bigger, other more technical and complicated solutions are present too.
see this link.

How can I send a notification?

I am developing an Android App that communicates with a server.
How can I send a notification from my server to my Android App without the use of C2DM?
Are Sockets a good solution? What are other alternatives?
I'd suggest you to develop a webservice preferably with JSON which is easy to handle. This server client architecture will hellp you to send and receive any kind of data (ranges from raw text to images or even video)
Check out C# webservices. That are very easy to start than the PHP services IMHO.
Depends on what you want to do.
have you thought on how does the server identifies the client to send the message ? In this case the android phone ?
With http you would need the client to "request" this notification.
The closest thing to an actual notification would be to have a socket connection, which the client would connect to the server. But then would require an existent connection between the two. If this is ok for what you are doing, then go ahead if you really want to avoid C2DM.
But, using C2DM allows your server to send notification to devices without a need for a request or direct connection from the client. The only thing you need to do is pass the identification of the device to your third-party server given when you authenticate with google's C2DM. After that, you just push notification data to C2DM and google delivers the notification for you.
I've used MQTT for providing push notifications on Android and it's proved to be a good, reliable, low power solution.
Some links to support my case / get you started:
http://mqtt.org/
Power Profiling: MQTT on Android
Basic Steps for Using MQTT in android

Java Android GPS send coordinates

I've got many Android devices and I want to create an application that will be able to send the GPS coordinates and some id of the device to a server created on a PC. what is the fastest and easiest way to do do that ? I tried to find some telnet or java spring rest template but couldn't find a decent tutorial.
please help
There are two steps
1) Getting the GPS coordinates
There are a multitude of examples on how to do this; look into LocationListener and read the Obtaining User Location section of the docs.
2) Sending this data to a server
You will probably use an HTTP Post to accomplish this. See e.g. this Android HTTP Communication post and HttpClient class.
As far as getting a unique ID, you can use the suggestion from another post and use Settings.Secure.ANDROID_ID http://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID

Categories