I found links GCM with PHP (Google Cloud Messaging) or http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/, both explain how to downstream data from 3rd party server to device(s) using cURL. But can anyone give me one example of how to upstream data from device to 3rd party server via php. Android provides us with both java and python(XMPP).
Cause my main task is to sync local db with remote db, so using SyncAdapter http://developer.android.com/training/sync-adapters/creating-sync-adapter.html
is a better choice over GCM
Related
I am using LAMP stack in my server and I want to send data from the server to the android device. The android device should not make a request to the server for getting the data , the server will send the data on its own and the android device should receive it using a background service. What should I do?
P.S -> I know GCM and parse.com do this using push notifications but is there any other way?
In General I can see only three options,
Make time to time requests from device to server
Use Google Cloud Messaging
Use a signal R client for android (if you need to use signalR you should use microsoft asp.net instead of LAMP )
I would like to recommend you GCM way. I haven't use Signal R in android native mobile applications but i have use it in web application development.
I have added some links above, hope it will help you.
I tried searching these issues. Some sites say I need to do some stuff with php in order to make 3rd party server while others don't mention anything. some says it need JSON. Guide me please. PS I am a beginner and know java, XML,SQL only.
You should only need one server. The second server you are reading about may be the Google GCM cloud server? When I did a GCM project a few years ago, I had one server, it happened to be a App Engine instance. It generated events and sent them to Google via the GCM api and then onto onto the device. I don't remember it being that difficult.
I did have more than one server in the mix though, there were others that sent messages to the AppEngine server, but it was not required to send a GCM message.
Google Cloud Messaging (GCM) is a service that enables developers to send data from servers to both Android applications or Chrome apps and extensions.
So if you want to send data to the users of your App then you must have an interface or dashboard from where you can send some data (typically push notification) to the users of your app.
This dashboard (server from which you can send data) can be developed by using PHP or any script languages.
Now a though can come up in your mind:
"I am suppose to develop both the mobile app and the server then what
role does GCM play?"
Yes, GCM is playing a vital role indeed. The server we have to develop is just to design an interface so that you can type your message/notification and select the recipients. Rest of the part of (managing the queue, communication with the apps checking for authentication and all other stuffs will be done by mighty GCM )
In order to have an bird-eye overview you can take a look on this image collected form android hive
Server side coding is doesn't need you to be expert in php. So you can go through to this article. It helped me a lot to learn.
Is it possible to send data from PHP server to all devices registered in the Google Cloud Messaging app without registering the ids of the devices in the PHP server db?
If not in PHP, is there other way to achieve this?
And one more question..
Which technology should I use to connect PHP Server with the GCM backend for manipulating a datastructure (within Cloud Datastore if necesary) that Android/IOS clients could subscribe to in order to receive PushNotification?
I'm looking for the best approach to send data(String) from my server (PHP) to one specific android device.
I can check the device if is online/offline on my server(with http-post method). But I don't know how to send data to spesific device without GCM. (I'm not looking for push notification and I'll send message to maximum 100 user.)
Without using GCM, you have several options:
app polls server for updates, at a specified interval. It may impact device's battery life and network usage.
app opens TCP connection to the server which is then used by server to send updates to app. I'm pretty sure it's not something you want to do in PHP, though.
server sends an SMS to the device (assuming it's a phone) and app intercepts it. This would require your server to know the phone number of the recipient and implies using some SMS API (usually paid).
app (WebView or web app) uses WebSockets to connect to server
use push service different than GCM (i.e. Urban Airship)
From all of those I would look into polling first. It's often considere somewhat a bad practice, but it's not necessarily the case. Have a look at this AT&T blog post for some measurements.
An other solutions is to use an MQTT .
Install MQTT in your server and create your queue.
Write to the queue in PHP with one of the PHP libraries : https://github.com/mqtt/mqtt.github.io/wiki/libraries
In Android receive the message with http://www.eclipse.org/paho/clients/android/
The communication is asynchronous and all work inside your LAN without external public service (like GCM).
I hope this can be helpful.
i'm trying to implement a chat application for android (where users can communicate people who are in same location). i'm thinking it of an facebook messenger with Geo specific oriented. i came across to terms like repeated pull, comet, bosh, websockects, socket programming, xmpp(which requires xmpp capable server like openfire) etc to do this. But my resources are fixed like apache, php (codeignter) and MySql only. I need to find the efficient to way to do this. Guys i need this. Please help me.
Thank you,
abbiya
The preferred approach on Android is Google Cloud Messaging.
Google Cloud Messaging for Android (GCM) is a service that allows you
to send data from your server to your users' Android-powered device.
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).
The GCM service handles all aspects of queueing of messages and
delivery to the target Android application running on the target
device. GCM is completely free no matter how big your messaging needs
are, and there are no quotas.
Essentially, it works like this: Your server talks to Google, and Google pushes the message in real-time (or nearly so, as long as the device is powered on and connected to the Internet) to the Android device(s). There's a registration process that happens on the Android device the first time the app is installed (and at future points to revalidate the registration). In your Android app, it's your responsibility to send this registration ID to your server so you can store it for future use. Your server uses this registration ID when it wants to push a message to that device.
The communication protocol between your server and Google is JSON over HTTPS. Your server can use any languages/technologies, as long as it can communicate with Google's servers. A PHP/MySQL application can definitely meet the basic requirements for the service:
Before you can write client Android applications that use the GCM
feature, you must have an application server that meets the following
criteria:
Able to communicate with your client.
Able to fire off HTTPS requests to the GCM server.
Able to handle requests and resend then as needed, using exponential back-off.
Able to store the API key and client registration IDs.
On the client side, the Android device must be running API version 8 (Android 2.2) or later. Of course, it's also your Android app's responsibility to process incoming messages (using a BroadcastReceiver, as the Android system sends an Intent to your receiver whenever a message arrives), which allows you to handle messages however you want.