Monday, May 30, 2011

Android Push Notification : My Method 1

Push Notification using IBM RSMB, MQTT & SAM PHP Script

Environment :

Eclipse Galileo,
Ubuntu 10.04,
Samsung Galaxy S Android Device
IBM RSMB,
SAM Php Script,
Sample App,



Steps to implement Push Notifications:

1. Running IBM RSMB Broker Service
A very small messaging server that uses the lightweight MQTT publish/subscribe
protocol to distribute messages between applications.

1.1 Download the IBM RSMB for linux
here

1.2 Extract the ZIP file to a handy location.

1.3 Navigate to Linux platform in the unzipped folder(linux_ia32/linux_ia64; I had
to use linux_ia64)

1.4 You should find 'broker' script file in the folder. Run it.
$./broker
You should see the console saying "IBM RSMB Broker started"


2. Deploying the SAM PHP Script

SAM is a drop-in PHP library for MQTT

2.1 Download the SAM PHP Script
here

2.2 Extract the contents to /var/www/pushn (pushn - create new folder under
/var/www) folder.
The folder contains 1.MQTT (Folder) 2.php_sam.php 3.sam_factory_mqtt.php
4.sam_factory_xms.php
MQTT folder contains sam_mqtt.php that is responsible for sending message to
RSMB Broker.

2.3 If you are still running the broker, browse for http://server-ip/pushn/
You should now see a web page, containing two text fields and Server status
Similar to this

3. Running Sample App on the device

3.1 Download and install the sample app on the device from this
url

3.2 Run the app and Start the Push service on the device : Click "Start Push
Service" button

3.3 Now navigate to the URL http://server-ip/pushn, enter your android device Id
and a message in the text fields provided in the site. Click "Send Message"
button and you should see the message in Status Bar Notification area of the
android device.


Notes :

* IBM RSMB is a paid service, but initially you will get to send about 40 (havent kept
the count) messages by running the broker in your public IP.

* I had developed a servlet that redirects the requests to SAM Php application.

* Was able to send JSON message from Servlet to Php, php to broker, broker to my
android device.

* RSMB is a very quick service, I almost got notifications within 3 seconds from the
time I sent from website.


References:

http://tokudu.com/2010/how-to-implement-push-notifications-for-android/

http://www.alphaworks.ibm.com/tech/rsmb/download


Best,

No comments:

Post a Comment