Server Side Code Implementation Using PHP
In this tutorial I have used PHP as server side programming language and MySQL database to store data. Since sending message from PHP to GCM is easy, here we'll be using CURL to create a message request to send for Google GCM server. CURL is a library that lets you make HTTP requests in PHP.
In this tutorial I have used PHP as server side programming language and MySQL database to store data. Since sending message from PHP to GCM is easy, here we'll be using CURL to create a message request to send for Google GCM server. CURL is a library that lets you make HTTP requests in PHP.
You can download the workspace from here. Extract the file to public html folder and modify the PHP files code as shown in below section to make PHP application work.
Open the config.php and enter the Mysql sever details where your Mysql DB is installed. Also change the Google API Key associated with Google project. Create the gcm_users table in the database, gcm_users.sql script is located in etc folder.
Developed the SOAP based Web service to receive device token/ registration id from ADF mobile and store that in Mysql database. Here I have used NuSOAP to create webservice, NuSOAP is a rewrite of SOAPx4, provided by NuSphere and Dietrich Ayala. It is a set of PHP classes - no PHP extensions required - that allow developers to create and consume web services based on SOAP 1.1, WSDL 1.1 and HTTP 1.0/1.1
Open the http://hostname/GcmService.php in browser, you can see the gcmService as showed below.
Push Notification provides a channel to push notifications to clients, and the notification payload can contain some limited set of parameter-value pairs that can be parsed by the ADF Mobile app, when you click on the notification message. In this example I am sending the payload as
"$message = array("alert" => $message, 'sound' => 'default', 'customMessage' => $customMessage);"
You can alter the payload in send_message.php. Once the users registered with GCM, http://hostname/index.php screen will looks as below.
Now you can send the Push Notification message to registered users.
Open the http://hostname/GcmService.php in browser, you can see the gcmService as showed below.
Clicking on the WSDL link will loads the Webservice WSDL URL - "http://hostname/GcmService.php?wsdl", which will be used in the ADF Mobile Push Notifications With Google Cloud Messaging (GCM) Part 1 to create Web service data control to send data back to provider application server.
Open the http://hostname/index.php in the browser, page loads with no devices is registered.
Push Notification provides a channel to push notifications to clients, and the notification payload can contain some limited set of parameter-value pairs that can be parsed by the ADF Mobile app, when you click on the notification message. In this example I am sending the payload as
"$message = array("alert" => $message, 'sound' => 'default', 'customMessage' => $customMessage);"
You can alter the payload in send_message.php. Once the users registered with GCM, http://hostname/index.php screen will looks as below.
Now you can send the Push Notification message to registered users.
Hi Deepak,
ReplyDeleteIt's really great example of push Notification. Can you just tell, how to implement that server side code implementation using java.
I'm working on this, will send you the code sooner.
Delete-Deepak
Thanks Deepak,
DeleteI created a java webservice to register devices and send notification and its working fine. But I am unable to send the notification in json format as your PHP service was sending...
Can you tell me how to send the Notification in Json Format as the PHP service
Hi Deepak, Thankful to your efforts towards ADF and ADF Mobile.
ReplyDeleteI developed Push Notification application as you said.But while i'm hitting WSDL(http://oraclebpm.com/GcmService.php?wsdl) in ADF Mobile Push Notification application, getting error is " HTTP Status Code 500 Internal Server Error: The server encountered an unexpected condition which prevented it from fulfilling the request" .
When the Same WSDL is hitting from ADF application and SOAP-UI getting no issues. Please help me how to debug and resolve the issue.
Thanks
Chandra
Hi,
DeleteLet me know you are using the Emulator/Real device. Check the proxy settings, If you are using the emulator this will not work since emulator you might need to set the vpn.
-Deepak
Thanks Deepak,
DeleteI checked this application in both emulator and samsung galaxy tab device , getting Same error.
(http://oraclebpm.com/GcmService.php?wsdl) This is my WSDL. Is there any wrong in WSDL?.
Please see the below link for application log messages in image format while it run on samsung galaxy tab device.
https://docs.google.com/file/d/0B1Agc3K-v10YdUlmdFdTdnZqbVU/edit?pli=1
Thanks
chandra
Hi,
DeleteSorry for the late reply, while using emulator/device with GCM you should not be in oracle network. Try to access outside oracle network it will work.
-Deepak
Hi Deepak, I am facing the same issue while implementing in our ADF mobile application.
ReplyDeleteAny help is appreciated...
Regards
Abhishek
Hi Abhishek,
DeletePlease find my comments in above.
-Deepak
// Disabling SSL Certificate support temporarly
ReplyDeletecurl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
if above line is not called, what kind of additional steps should I take to make it work?
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); FALSE to stop CURL from verifying the peer's certificate. Alternate certificates to verify against can be specified with the CURLOPT_CAINFO option or a certificate directory can be specified with the CURLOPT_CAPATH option.
DeleteHi Deepak,
ReplyDeleteThanks for the tutorial. I have successfully sent a hello world notification to my android phone. But in my notification center, my app's entry only has an icon and the app name. There's no message in the place where you display your "alert" => $message.
I wonder where and how to configure the alert message to be shown the notification center? (before the notification is clicked or dismissed.)
My POST request to GCM has a payload looks like follows
{
registration_id : "",
data : "Hello World"
}
and my onMessage(Event e) method would return "Hello World" when I call e.getPayload();
Thanks for the help.
Hi Deepak,
ReplyDeleteThanks for the post. I am exactly trying what you have mentioned here to see how push notification works in adf mobile. I have done with Part1 and now to create server side program ,I have downloaded workspace which you have given here.
you have mentioned that we need to extract that to public html folder but which public html folder do we need to ?and i have Oracle XE database, so can i provide same details in the config.php file ?
And i am not sure how to create soap webservice using NuSOAP, could you please explain those steps. and can we deploy to integrated web logic server? Please help.
Thank you.
Hi,
DeleteServer side I have created using PHP, so you will not be able to deploy that to integrated web logic server. Above sample can be used with LAMP technologies.
Again NuSOAP is a PHP supporting library to create webservice. I'm not getting time to create the same application in Java, once I create I will share you.
-Deepak