not being able to establish device-to-device messaging using GCM - php

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

Related

send notification to android device from server without GCM(Google Cloud Messaging)

I have to send notification from server to android device. I developed application which got notification from server by using GCM (Google Cloud Messaging). But as I already have server then why to use GCM. I am not getting the purpose of using GCM. Can we send notification from server to android application without using GCM.
General Communication Pattern :
Device --> HTTPRequest -- >Server , Server -->HTTPResponse --> Device
But in this case, the device gets a response only when you send a request from your device to the server. Hence, whenever you need something new from your server you need to make a
request.
Using GCM, you do not need to make this request explicitly to your server. You'll automatically be notified when something new happens (depending on your implementation).
You are having server but GCM is totally different thing then your server.
GCM will monitor Your Application server that any changes made or not ??
And if anything created then it will send you notification without refresh or reload the Application.
and GCM will send you notification when your application is not working as well

What should I use to develop a simple messaging service in Android application?

I am very new to Android programming and I am trying to make an app that enables users to send and receive messages. I already have a database and Apache set up. I've already implemented login, registration of users and adding friends to chat with.
Now in order to send and receive messages, do I use Google cloud messaging service? But GCM requires to set up the backend on Google cloud, right? I already have a working backend, so how can I use my existing database and Apache server to implement messaging? Should I write a PHP script to send and receive messages to/from Android devices?
But GCM requires to set up the backend on Google cloud right
No you don't need a backend on Google Cloud. What happens is that you use your own server (called "third-party server" in their docs), to send messages to Google's GCM server (using CCS protocol) which relays it on your behalf to the phone.
The same happens in reverse: the phone sends messages to Google's GCM server which relays it back to your server.
Here are the docs on getting you started:
Client implementation
Server implementation

Google Cloud Messaging example

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

Push Notification using GCM - PHP

I am trying to implement Push Notification using GCM,
Besically i am trying to send Notification to the GCM using my PHP server which will deliver it to my android application.
I have used code at androidhive!
The device is getting registered successfully but i am not receiving any notification at my device nor anything is visible at Google console.
I am not receiving any response from the link used https://android.googleapis.com/gcm/send or https://android.googleapis.com
Is there anything wrong in this approach?
Can anyone suggest me any authentic source for this?
Realizing that some people are facing issues implementing GCM. I have decided to post solution.
The example on AndroidHive is working perfectly. Its just the matter of correct configuration.
Replace project ID in Android app. (You can get project ID from you google's console link i.e google.com/apis/console/#project:xxxxxxxxxxxx:access)
Replace Server API Key on PHP Server(config.php)
Key for server apps (with IP locking).
You can get your IP from WhatIsMyIP.
Key for browser apps (with referers) will not work.

C2DM and PHP Server

I'm trying to write the server side of my android app that uses C2DM. I'm going to write it in php. I basically am just doing tests right now. I copied the chrome to phone example for the actual android app and modified it to my liking. Right now my biggest question is the registration.
Let me get everything straightened out.
When registering the device for the first time, the app talks directly to my server. The server grabs the deviceid and responds back with a 200. Right?
So, on the php side of things, I grab the device id like $deviceid = $_POST['deviceId'] Right?
add it to my database. then respond back to the app.. How exactly do I send a particular response back? I assume in the header? I'm unsure how to do that.
Please confirm or deny that I'm on the right track and clear up any confusion.
Thanks for the help.
You don't respond back to the app. You must register your server with google's servers to get a server authentication token. You then use that server token and the device token in a post request to google's C2DM service to have google's servers send a push notification to the phone. Your app and your server never directly communicate when a push notification is sent in C2DM, it is all done through google, yet you need to implement a mechanism for your server to know the device id of the device it wants to send a message to.
This is a pretty detailed guide, though the server code is in Java:
www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html
Make sure you have really gotten the IDs before sending to the server. If you are using an emulator for testing, you could do an echo over at the php script so the message will appear in your logcat.
Google refreshes expired registration IDs so your application should be able to pick up new notifications/ids from google and handle the message by sending to the database.

Categories