For a long time, I have been wanting to design a simple chat app based on Google Cloud Messaging. I know that the server supports a direct payload of 4kB.
I just need to connect to specific phones through this app, just for a small project.
Do I need a seperate PHP server to help in this matter? Or does mating GCM with Android API provide the necessary protocol of achieving this?
Can you please help me?
Thanks in advance
well you need one server not in php compulsory but in some other lang that gcm support like java
its flow is some thing like
1 app get the registerid for gcm server
2 send that to your server where it store it
3 when you want to send a message to other app your send that message to your server
4 your server send a request with the target registeration id to gcm server
5 gcm send the message to the target app
Related
Well let's question, I need to develop for my term paper a messaging system where I can from my site / php server send messages to my android application. I know the question is very broad, but I wanted to know the simplest way to achieve this. Someone could show me some method or API to achieve.
PS: Sorry for english
I thank you
If you want to receive messages in your app while the app is terminated or running you could use the Firebase Cloud Messaging.
Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages at no cost.
Using FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user reengagement and retention. For use cases such as instant messaging, a message can transfer a payload of up to 4KB to a client app.
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.
I am trying to establish device to device messaging using Google Cloud Messaging. I tried using socket programmng, but the connection used to get lost everytime I moved to the next page. Thus I am using GCM. The plan is to send a message from client's phone and it should be displayed on server's phone, using 3g/wifi and not bluetooth.
I am referring the following link for the same:
http://androidexample.com/Device_To_Device_Messaging_Using_Google_Cloud_Messaging_GCM_-_Android_Example/index.php?view=article_discription&aid=122&aaid=142
It has no errors and is running, but nothing is displaying on the screen. Also a few doubts:
In the code in CommonUtilities.java what should be the Server_Url? I am using XAMPP, so should it be XAMPP's URL?
Also, what should be the Sender_ID?
Also in MainActivity.java, what should be the device IMEI? Do we have to enter that manually, or will the device fetch on ots own.
Also in the php files, its written enter "GCM Registeration ID got from device".Is it client's ID? I am running using Google API and registering my ID in the settings of the emulator before proceeding further.
Can anyone please tell me where am I going wrong? Or even if you have a better idea, please do share here. I am looking for mobile to mobile communication only, not using push notifications.
GCM is working as follow:
1/First of all you have to register your application in google and get your Sender_ID
2/the client connect to GCM cloud in order to register it self (using the SENDR_ID)
3/GCM cloud send a registrationID to the client
4/You should make a server so that you save the registrationID of any device that runs your apps
If you want to send a GCM notification from one client to server
1/the client should connect to your server
2/tell the server to make a demande to the GCM cloud containing the registrationID of the server so that the GCM send the notification to the server
you will find a detailed explanation here
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.
I need to make chat application for android. I thought of using PHP script to implement the chat application. Basic idea is to send message form android client to PHP script and making use of PHP script send the messages to the MySQL database. These messages will be broadcasting to other people. But the problem is auto broadcasting messages to other people. Is there a way to do this using android and php?
You can do the following
Make a persistent tcp connection between your device and the PHP server
When a message is broadcast send it over the tcp connection of each device
On the device process this notification and you are good to go.
If you want to use Java on the server side I have your project already finished and ready to ship ;) (just kidding)
But if you are interested check out the Device-To-Device messaging framework of OpenMobster Mobile Cloud platform. The project is free and open source. Here is a link to the Device-To-Device Framework: http://code.google.com/p/openmobster/wiki/D2DPushFramework
and http://code.google.com/p/openmobster/wiki/PushFramework
The above three steps are already taken care of by the framework. The developer just has to focus on the App itself
Good Luck!!!!
Yes there is several ways to do this
you can just post to the server and from the server send push notifications to the mobiles
You can make the mobile keep checking for updates if it exists
You will require to finish these steps ( at least ):
setup a PHP web server
register for Android Push Notification (you probably need that)
create database schema
write your own codes to allow users to submit & retrieve chat messages
security !!!
You'd probably want to use Google's C2DM, though it's not free.
Your php server would get a message from a phone, do it's processing, then make a HTTPS request to Google's C2DM service, which sends the messages to the destination android device.
http://code.google.com/android/c2dm/#push-process
Don't use C2DM, its a deprecated. Please go through the GCM(Global Cloud Messaging),
please follow this link,
http://developer.android.com/google/gcm
Have you heard of Firebase? Firebase. Making a chat app with Firebase is like eating pizza.