Hello everyone. In this post I will try to provide you with a quick example on how to implement push notifications for your Android app using MQTT protocol. I will NOT discuss here why an application might need push notifications or the advantages of Push over Pull. I assume that you know exactly what I mean by push notifications are and why you might need them. However, before jumping in straight to the good stuff, let’s go over how it all started.
Introduction
It’s been around 4 months now since I’ve started developing apps on the Android platform. It began with me scoring a free Nexus One phone at one of the Android Developer Labs. Obviously, I couldn’t resist trying to hack around with some code, so I downloaded the SDK and dove in. I guess in some sense, that’s exactly what Google was hoping for when they starting giving out free phones. While it might sound like I got lucky, in the end Google is the one who won.
Anyway, developing for the Android platform turned out to the a pleasure. The SDK was easy to setup, easy to use and and easy to understand. Putting together your first app was a breeze. I was very impressed.
Unfortunately, I soon realized that Android is not perfect. One of the things that really disappointed me was the lack of a native method for performing push notifications. Over the past year push notifications became almost a standard in the mobile space thanks to Apple. Even though BlackBerry utlilized Push since god knows when, it was Apple that really brought Push mainstream. Obviously, lack of native Push on Android seems like a huge drawback. Naturally, I started looking around for a solution. After Googling through dozens and dozens of blogs and message boards, I’ve realized that there are 3 generally accepted ways to implement push notifications for your Android app. All of which are non-trivial, hacky and have their own disadvantages. Let’s go over the list:
- Poll? The name obviously tells you that it’s really not even push. The idea here is to periodically poll the server for new messages from a background local or remote service. The more often you poll the closer you get to the real-time push.
- SMS Android allows you to intercept SMS messages. Your server sends a specially encoded SMS to your phone, whenever there is something new. Your app intercepts all messages, looks for the ones from the server, then pops up a notification.
- Persistent TCP/IP The phone initiates a long-lived mostly idle TCP/IP connection with the server and maintains it by occasionally sending keepalive messages. Whenever there is something new on the server, it sends a messages to the phone over the TCP connection.
The first two methods have significant disadvantages that we cannot do anything about. However, the third method’s drawbacks are not as severe. It seems like with enough work and a good design, the persistent TCP/IP method can work. After all, that’s how GMail, GTalk and Google Voice implement their real-time updates. In fact, many developers out there agree that it is probably the best way to go until Google actually takes the matter in their own hands.
Persistent TCP/IP
After more Googling around I was able to come across three reasonable efforts to implement push notifications using a persistent TCP/IP connection:
- Josh Guilfoyle talks about how to create a most-idle TCP/IP connection with a long keep-alive timer based on the AlarmManager. He provides some really cool sample code with a service that runs in the background and makes connections. http://devtcg.blogspot.com/2009/01/push-services-implementing-persistent.html
- Dave Rea recently started the Deacon project, which is aimed at developing a 3rd party library for Android push notifications using comet technology based on the Meteor server. The project is still in a very early stage (at the time of this post), but looks quite promising. http://deacon.daverea.com/
- Dale Lane had done a number of presentations, where he talked about using the IBM developed MQTT protocol for implementing Android push notifications. He also provides some really useful sample Android code. http://dalelane.co.uk/blog/?p=938
While all of the work done by these guys is incredible, none of their results are quite ready for drop-in use by other developers. In my effort to implement push notifications, I decided to put the pieces of the puzzle together and combine their results to produce a relatively stable way of implementing push. The example that I provide you with further, is a combination of Josh Guilfoyle’s TestKeepAlive project and Dale Lane’s MQTT work. I borrow quite a bit of code from those guys, so they should get most of the credit. Anyways, enough for the introduction, let’s get to the good stuff.
My Idea
The problem with the TestKeepAlive project is that it creates a raw TCP connection, which means that you need write your own server to take care of push on the other side. While it’s, without a question, doable, it is exactly why TestKeepAlive is far from a working solution. On the other hand, the MQTT example shown by Dale Lane uses the IBM’s MQTT broker to handle the server work. To backup a little, MQTT stands for MQ Telemetry Transport, which is a protocol developed by IBM. Let’s take a quick look at the man page:
mqtt is a publish/subscribe messaging protocol intended that is designed to be lightweight. It is useful for use with low power sensors, but is applicable to many scenarios.
Did you see the part about ‘low power’? So did I. Basically, the reason why one might consider using MQTT is that it was designed to be very lightweight, so that it doesn’t consume much power. This is ideal for a mobile push solution as it addresses many battery life related concerns about persistent TCP/IP connections. Obviously, MQTT also has some disadvantages such as privacy, but we can talk about that later.
So, my idea consists of taking a KeepAliveService and replacing the raw TCP/IP connection with an MQTT connection. In this case, each device can simply subscribe to a unique topic which is based on its device ID. Now, assuming that your server knows the device ID, it can push data to the device over MQTT by publishing to that unique topic.
Architecture
In my example, I utilize a PHP script as a server. This uses the Simple Asynchronous Messaging library (see project SAM http://project-sam.awardspace.com/) to publish MQTT messages to the broker on which I host on my server. Let’s have a look at the overall system diagram:
wmqtt.jar is a simple drop-in implementation of MQTT protocol provided by IBM. It can be downloaded from http://www-01.ibm.com/support/docview.wss?rs=171&uid=swg24006006. The file that you download has a bunch of different stuff. Just look for the right jar file. You can include this jar as a part of your Android app.
Really Small Message Broker (RSMB) is a simple MQTT broker also provided by IBM http://www.alphaworks.ibm.com/tech/rsmb. It runs on port 1883 by default. In our architecture it accepts messages from the server and passes them on to the right devices. RSMB can also be replaced by the Mosquitto server http://mosquitto.atchoo.org/.
SAM is a drop-in PHP library for MQTT and other stuff. You can either get it as PECL extension or download the source online http://pecl.php.net/package/sam/download/0.2.0.
send_mqtt.php is a simple PHP script that accepts messages over POST and uses SAM to pass-on messages to the broker.
Sample Code and Demo
The goal of my work on push notifications was to develop a working demo, which is what all other examples out there lack. I’m happy to say that I accomplished my objective. You can download the sample android app on GitHub.
This app (shown on the left) has a TextView and two buttons. The TextView contains your device ID and the buttons are used to start and stop the push notifications service. Once you have the app on your phone, start the service. Then go to http://tokudu.com/demo/android-push/ and enter the device ID in the first text box and enter the message text in the textarea below. Press “Send Push Message” and you should get a notification on your phone. It’s as easy as that.
You can see the source code for andoid-push in this GitHub project. It contains the aforementioned send_mqtt.php script.
If you didn’t get a notification, make sure you have network connectivity. It can also be that the broker is down on my server (see server status on the page). If that’s the case, please post a comment and I will look into it bringing the broker back up.
Final Thoughts and Comments
MQTT is definitely not the best way to implement push for Android, but it does work. One of the main drawbacks of MQTT is that anyone who knows the IP and the PORT at which the broker is running can connect and intercept your Push messages. So it’s probably a good idea to encrypt them. Alternatively, you could write your own broker and introduce some sort of authentication to MQTT.
The code I provide here for the push service still needs more testing. Reliability is definitely the main question. I think the code can definitely be improved to better handle connectivity loss and other erroneous situations. You are welcome to post your comments here regarding how it can be improved.
Also let me know if you find any bad bugs. Good luck testing!
Anton Lopyrev
Follow me on twitter @tokudu



May 16th, 2010 at 2:43 pm
[...] MQTT for push in Android apps, you’ll probably want to head over to Anton L’s blog post How to Implement Push Notifications for Android. He has a sample Android app that uses the IBM Java library to implement push notifications using [...]
May 18th, 2010 at 7:10 am
Anton –
Great post. Push Notifications will be a growing part of the application eco-system. Particulalry on Android where messaging can be incredibly rich (including intents).
At Xtify we have seen real adoption of our SDK by developers eager to take advantage of the Android OS.
Our service provides for FREE push notificationa to Android devices. Any developer can download our SDK, compile into their application and immediately have a full push platform available.
Our service is free because we expect that over time the analytical and geo tools we are building will be more valuable.
You can have a go at it here: developer.xtify.com
May 19th, 2010 at 12:52 pm
Thanks Anton! Your post took me a big step forward. I used mosquitto as message broker. Got my proof of concept working without problems based on your article.
Regards
Klaus
P.S.: I found the smiley at the bottom of this page.
May 20th, 2010 at 7:36 am
Good job. Many thanks.
P.S. server is down.
May 20th, 2010 at 8:51 am
Thank you, it should be back up now
May 21st, 2010 at 11:56 am
Nice work, however you were right Google did take matters into their own hands and the Android Cloud to Device Messaging Framework is poised to be the defacto standard for push messages.
http://code.google.com/android/c2dm/
May 21st, 2010 at 12:26 pm
I’m very excited of try it out. However, if you wish your app to support devices 1.5 + you might still consider using mqtt.
May 23rd, 2010 at 4:27 am
very interesting post, i’m actually looking at those different solutions. yours seems very good, but did you try xmmp solution with the asmack library?
Android Cloud to Device Messaging Framework works from android 2.2 and i am targeting sdk from 1.5.
Furthermore, is mqtt implementation a good solution if i want differents devices to communicate to share data or multimedia sessions, i think that xmmp with jingle could maybe do the trick. I’m still investigating so do you have any idea of a simple way to do this?
May 23rd, 2010 at 10:43 am
XMPP could be a viable solution, after all, that’s what Google Talk is based on. I think it uses libjingle. I haven’t played around with it myself, but I have seen it on blogs online. Take a look at this for instance:
http://credentiality2.blogspot.com/2010/03/xmpp-asmack-android-google-talk.html.
Let me know if you get it to work nicely.
May 24th, 2010 at 10:00 am
actually, it works pretty well. i do use google app engine for the native xmmp client service allowing 1 milion plus notifications. xmpp smack client on the devices and an xmpp serveur. only thing is i got some annoying timely disconnections but i’m working on it actually.
I’m about to try mqtt to see which one is easier to deploy and maintain. I’ll let you know.
Other thing interesting with xmpp is the implementation of multimedia session between users, but not yet on the mobile devices library i guess.
May 25th, 2010 at 4:38 am
Thanks Anton.
You got me working and gave a direction…..
May 29th, 2010 at 11:58 am
Thanks! Tokudu!!! I got many helps.!!
but, I have a problem.
This demo app was running very well one week ago, but now is not running.
In other words, When I enter site ” http://tokudu.com/demo/android-push/ ”
and click “send push message”, my android phone doesn’t react.
Have to I re-install demo app??? or server port number change???
I don’t know what problem is. I need your help~
May 29th, 2010 at 12:57 pm
Hi there,
Try re-downloading the source code from GitHub. I changed somethings, so that’s why it’s probably not working. I just tested it myself, it’s working fine for me.
Good luck.
June 3rd, 2010 at 12:53 pm
Hey,
I was just wondering if mqtt (mosquitto for instance) allows multiple subscriptions from the same IP, but to different topics? I seem to get disconnects when I try to connect though to a different topic.
June 5th, 2010 at 5:04 pm
Yes it does. However, you need to make sure you have a different client name.
June 7th, 2010 at 9:53 pm
Fantastic post, thanks thk! Just wanted to mention that for some reason on my Nexus One, the “connectivity changed” event fires as soon as the service starts and makes the client think that the network connection has been lost. I had to comment out the “registerReceiver” and “unregisterReceiver” lines to get it to work. It works great now though (until I lose network connectivity, I suppose).
June 9th, 2010 at 11:56 am
Hi,
I succesfully made an apk of the sourcecode and i can start the application on my HTC desire. However when i fill in the device id and message on your website, the notification will not be displayed.
Do you know why this happens?
June 9th, 2010 at 12:45 pm
I have copied your code over to a scripting service that is “hosting” my page. I changed only the IP address to be the one where my page is hosted (I think). The problem is when I try to use it, the page comes up but it says that it is offline. I turned debug on and it says: Server status: –>SAMConnection_MQTT()
<–SAMConnection_MQTT(). What should I look at or what could be my problem?
Thanks for the wonderful tutorial by the way.
June 9th, 2010 at 1:57 pm
[22:42:20] Opened log.
[22:42:20] Service started with intent=Intent { act=tokudu.START cmp=com.tokudu.demo/.PushService }
[22:42:20] Starting service…
[22:42:20] Connecting…
[22:42:21] Connection established to 209.124.50.185 on topic tokudu/200145745b9784f9
[22:42:21] Connectivity changed: connected=false
June 9th, 2010 at 2:21 pm
@ alan: what version of PHP are you running? Try to turn on your warnings and see what’s being output.
@Joene from the log file it looks like it connects successfully, but then the network connectivity is lost. Have a look at Geoff’s comment above, he might have had a similar problem. Seems like the connection monitor is experiencing some issues. You can try to rework some code near “BroadcastReceiver mConnectivityChanged” and see when it starts working for you.
June 10th, 2010 at 11:10 am
PHP API 20041225
PHP Extension 20060613
If this isn’t what you want go to the following webpage where there is a lot of information:
http://alanma.scripts.mit.edu/QotD/
also: what address should I use for
fsockopen(ip_address, 1883);
I think my problem is occuring because that returns false
June 10th, 2010 at 11:58 am
found this also: PHP Version 5.2.13
June 10th, 2010 at 12:15 pm
Notice: (alanma) Use of undefined constant SAM_HOST – assumed ‘SAM_HOST’ in index.php
Notice: (alanma) Use of undefined constant SAM_PORT – assumed ‘SAM_PORT’ in index.php
Warning: (alanma) fsockopen() [function.fsockopen]: unable to connect to 18.98.4.32:1883 (Connection timed out)
I’m guessing I have the IP wrong… How can I find out what address to put there?
June 11th, 2010 at 12:13 am
Hi Anton,
I am having following problem when i deployed the php script..
Server status:
Warning: fsockopen() [function.fsockopen]: unable to connect to 127.0.0.1:1883 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ) in C:\wamp\www\tokudu\SAM\MQTT\sam_mqtt.php on line 640
Fatal error: Maximum execution time of 60 seconds exceeded in C:\wamp\www\tokudu\SAM\MQTT\sam_mqtt.php on line 640
Am i missing something here…
I am using wamp server which has php 5.3.0
June 11th, 2010 at 12:27 pm
There’s a bug in the SAM MQTT code – they assume that the network data reads are always of the correct length. This can sometimes cause problems with mosquitto for some reason, which might be the reason for the disconnections. This is discussed briefly (including a fix) at http://chemicaloliver.net/programming/mqtt-mosquitto-and-php/
June 17th, 2010 at 3:19 am
Sir,
The blog entry was extremely helpful to get started with Push notifications.
I spent some time looking into the basic function calls to push messages via the IBM really small broker.
I have a query.How did you make the ‘push messaging’ localized to a specific device id?..The publish function for the client has only four parameters namely
Topic,payload,qos and the retained flag i.e.:
“publish(java.lang.String thisTopic, byte[] thisMessage, int thisQoS, boolean retained)”
Since the source of the IBM broker is not available , how is the default broadcasting of the broker stopped and ability to push messages to a particular device with a specific device id can be implemented?
June 18th, 2010 at 11:13 am
@veejayc You need to change the IP address to the IP address of the server, where you have the MQTT broker running.
@Roger Thanks for that link. I was wondering why the mosquitto server was not working for me.
@Varun, I embed the device ID as part of the topic. Have a look at the source code
June 23rd, 2010 at 5:21 am
Thanks for your helps!
and I have a question.
Instead of using PHP and PHP library, is it possible to implement server layer using java and java library or api?
if possible, do you know solution?
thanks.
June 23rd, 2010 at 6:07 pm
Yeah for sure! You can simply use the same wmqtt.jar file that you include as a part of your android app and use the same function calls.
June 24th, 2010 at 8:09 am
Just wonder do you need to have the app running to receive the push?
Thanks
June 30th, 2010 at 11:53 pm
thk thanks for your extreamly helpful blog!
I’ve testing the push notification on my HTC Desire and it worked just fine two month ago but now I don’t receive the notification. Is there any problem on the server? or is it just me?
July 1st, 2010 at 1:36 pm
Thank-you for the extremely informative post Anton. At the end of your article you say that MQTT is not the best way to implement push for Android, is there a better solution?
Paul
July 15th, 2010 at 8:49 am
Thanks a lot for helping the community !!
So i started to make some work based on yours, to be able to make broadcast and terminal to terminal communication, but i’m worried about something.
Is there any limitation (other than with my own server) in the “(SAM+MQTT) solution” on the number of clients that can be registered at the same time ?
PS And about other limitations, if it can help some people, i saw the MQTT client ID cannot be more that 6 characters (the target part before the slash).
Thanks, and congrats again for the work !
July 21st, 2010 at 9:01 pm
MQTT does have a limitation on the number of clients, but it’s due to the number of sockets that the Linux kernel supports. By default it’s around 1032, but it can be changed in the kernel to a really large number when needed.
The MQTT client ID limit is I believe 8 characters, or smth like that.
July 27th, 2010 at 12:36 pm
For those of you that prefer a simple implementation and/or are not interested in maintaining your own servers, give Xtify a try.
Xtify is an out-of-the-box push notification service – download and include the Xtify SDK with your application. Then you can use our web console to configure message campaigns or call our webservice for system / device generated messages.
You can even create geo-triggered push notification campaigns by adding some locations and rules.
Xtify is also compatible with iPhone and Blackberry so you have one place to push across your entire user base.
August 2nd, 2010 at 11:08 pm
[...] How to Implement Push Notifications for Android (tags: mobile android rtw) [...]
August 6th, 2010 at 4:13 pm
A clarification: according to the MQTT spec, the length of the client id should be between 1 and 23 characters. Mosquitto doesn’t enforce the upper limit though.
I can also comment on the limitations on the number of clients that can be connected to a broker. I believe (although I may be wrong) that RSMB is limited to approximately 1024 clients connected at once. Mosquitto on the other hand is capable of having greater than 1024 clients connected, although this needs a small amount of configuring on the server to increase the limits imposed by the OS.
August 10th, 2010 at 3:04 am
How to Implement Push Notifications for Android
August 11th, 2010 at 7:51 pm
Tokudu Android Push Demo:
PHP Version 5.2.10
Apache 2.0 Handler
Server status:
Warning: fsockopen() [function.fsockopen]: unable to connect to 127.0.0.1:1883 (ѕопытка установить соединение была безуспешной, т.к. от другого компьютера за требуемое врем€ не получен нужный отклик, или было разорвано уже установленное соединение из-за неверного отклика уже подключенного компьютера. ) in C:\SERVER\www\lesson\android\PhpMQTTClient\SAM\MQTT\sam_mqtt.php on line 640
August 24th, 2010 at 1:53 am
Handling Notifications…
What support do platforms provide?……
September 1st, 2010 at 9:34 am
I did some TCP/network level analysis on Google’s c2dm/Gmail push application. This may be a nice complement to understanding Push-based services.
http://multicodecjukebox.blogspot.com/2010/08/androids-chatter-with-morthership.html
September 19th, 2010 at 7:46 pm
@Alex: you are trying to connect to localhost. You should be running an mqtt broker
@Sachin, I think your think is broken.
October 7th, 2010 at 3:59 am
[...] blog post on tokudu.com was amongst the top results in Google and provides a detailed walkthrough of the various [...]
October 7th, 2010 at 4:10 am
This post has been very helpful. We explored the various options you outlined but there are some issues with using MQTT.
- Your app still has to maintain an open connection and that uses up a lot of battery if other apps are doing the same.
- It requires the app to maintain connections to your servers on a custom port with a custom server. This makes it difficult to load balance and scale. It also requires opening a custom port and handling that kind of traffic. Our service currently operates entirely over HTTP/HTTPS and we like it that way. Communication with custom services like Apple is outgoing only.
- The protocol is open by default. This means “anyone who knows the IP and the PORT at which the broker is running can connect and intercept your Push messages”, unless you write your own authentication.
We eventually ended up using Urban Airship but we’re going to be implementing C2DM too. I’ve written up a tutorial at http://blog.boxedice.com/2010/10/07/android-push-notifications-tutorial/ that covers the options you mentioned and provides code samples and instructions for using C2DM.
October 7th, 2010 at 2:43 pm
MQTT definitely has issues. I mentioned that in the end of my article. It does work for a number of use-cases. With a number of advancements it can serve as a decent scalable solution for all Android versions. In fact, I implemented it in a number of production apps on the market.
When I wrote this tutorial, C2DM was not available yet. I would definitely recommend exploring C2DM as it’s scalable right off the bat. However, my main issue with it is that it only works for 2.2+, which is under 30% of devices out there.
October 22nd, 2010 at 2:19 am
thk thanks!
it works on android emulator. but on the phone, it is not….
in MQTTConnection method, I can’t get connection.
this is the part of the problem
mqttClient.connect(clientID, MQTT_CLEAN_START, MQTT_KEEP_ALIVE);
is there a better solution?
October 24th, 2010 at 8:09 pm
[...] came across this great blog post by Anton Lopyrev on implementing client/server apps, with push notification on Android, using the [...]
October 28th, 2010 at 8:17 am
I really liked this implementation and I intend to use it for a project I am working on. However, I had the same problem as Alan. I am very new to php at the moment and excuse my ignorance on this but i have literally copied and pasted the php source code onto my LAMP. It runs fine but just says offline. What do i need to do to get this working so that I can better understand the processes? I am willing to put the work in for this i just need a little direction. Am i correct in thinking i need to install a broker in addition to the php files? help!
October 28th, 2010 at 9:49 am
Ok i installed the brooker and its showing online. Apologies for the preemptive questions. Just a bit of panic trying to get my head round this.
November 10th, 2010 at 2:11 pm
Great intro for proof of concept.
Successfully deployed on Lenny.
Best of luck w/kik, looks like a well received app, we have all only begun!
November 16th, 2010 at 3:34 am
[...] [...]
November 17th, 2010 at 12:44 pm
Great stuff, i like the tut i like you share all parts of the implementation, have not tested it as i do not have a droid. It all sounds and looks simple clean and easy, whit the low level implementation that i need just right. Thanks a lot.
November 25th, 2010 at 2:08 pm
How can I know the client can recieve the message? what should I do or where I have to edit some code and which files, I’m very new to php. please help.
November 29th, 2010 at 6:40 pm
Great work!
I can’t seem to receive the notification on my handset though, your server says it is up, and I tried sending the push message both with and without starting the push service.
Do I actually have to do anything other than compiling/installing the app on my phone? Thanks.
December 1st, 2010 at 3:44 am
[...] http://tokudu.com/2010/how-to-implement-push-notifications-for-android/ [...]
December 2nd, 2010 at 11:37 am
Hi Q,
I’ve been experiencing some problems with my server lately. Your problem might be related. Please try again.
Anton
December 11th, 2010 at 4:06 am
sir,
i have problem to what we use SAM port and ip and also broker ip inthis example.is it necessary to use 1883 port ?
pleasssssssssssssssssse sir give me response.
December 16th, 2010 at 12:10 pm
Hi,
THK the information you have provided is worth for reading. Good job.
Besides that, I am getting a ‘Null’ of Secure.ANDROID_ID while testing on emulator. Searching blogs I found a work around to generate a unique key but seems like that key is not working for my emulator to registration on your push server. Plz help.
Nomus
December 20th, 2010 at 12:03 am
Hello,
Thanks for the wonderful tutorial.
Could you please tell me how do I send hidden custom data along with the notification and also how do I read this data with in the app once it is opened as a response from user.
January 18th, 2011 at 9:16 am
Nice tutorial. This is very helpfull for me.
I have a simple question.
How can I run Really Small Message Broker (RSMB) on my website?
I buy the virtual host on bluehost.com and they said they can run this serivce for me.
I just wonder how can you run it on this website?
Thanks in advance.
January 20th, 2011 at 3:46 pm
@Andrew: tell the tech guys to goto http://www.alphaworks.ibm.com/tech/rsmb and look at the right section where it says download
January 24th, 2011 at 6:16 am
Hi, first off – fantastic walkthrough. Really appreciated reading.
I have one question: Is there any possibility (with any push2device service) to get all the connected devices from the server? We need this information – unfortunately.
Many thanks in advance
January 26th, 2011 at 7:49 pm
I don’t think RSMB support that. However, if you work with Mosquitto server, it’s open-sourced. You can probably hack that it.
February 1st, 2011 at 3:16 am
Plz help me how to implement the server to store the registration id
February 7th, 2011 at 4:46 am
Great tutorial tokudu ! It was straightforward to experience notifications with my android thanks to you
When my android is connected to 3G, it’s working fine.
However, when my android is connected to WiFi, I can’t receive anything (the broker received the message, but could not send it).
Do you a hunch on that ? Would it be possible that my router blocks the notifications ?
February 24th, 2011 at 6:25 am
Can you give the address in order to download the code source
thank you!
February 24th, 2011 at 10:21 pm
thanks for your great blog!
I’ve downloaded zip code and it worked just fine before 2 weeks but now I can’t receive the notification. application crashes
showing…..
Connecting…
Sending signal. PID: 1965 SIG: 3
threadid=3: reacting to signal 3
Timeout executing service: ServiceRecord{44436fa0 com.tokudu.demo/.PushService}
Wrote stack traces to ‘/data/anr/traces.txt’
……………………………………
…………..
and finally
MqttException: NULL
please help
March 3rd, 2011 at 12:54 pm
@ rojy: Is that an error in the android app?
@EZZeddine: it’s at github: github.com/tokudu
March 4th, 2011 at 12:36 am
Hi, very interesting!
I have tried implementing push notification as described in the article, and it works fine in my HTC Android 2.2 mobile, thanks tokudu! Notifications are displayed in the status bar in near real time. However, if I send a notification to the mobile during an ongoing, outbound call, the notification gets delayed. Sometimes it takes just a few secs but sometimes even 10, 20, 30 seconds till the notification is displayed on the status bar. I need the notification in near realtime during ongoing calls to do multimodal types of applications. Is there a way to elliminate this delay?
March 7th, 2011 at 8:11 am
[...] Example of using mqqt for push notification on android: [...]
March 7th, 2011 at 9:41 pm
@gunbyl I haven’t really tested the notifications during an ongoing call. I can’t think of any place my code would act differently during a call. I will put it on my to-debug list. Sorry that I can’t be more helpful at this time
March 7th, 2011 at 11:02 pm
[...] a year ago, when I was playing around a lot with Android push notifications, I was a looking for a good hosting solution that would give me lots of flexibility of running [...]
March 10th, 2011 at 7:30 am
The above approaches will absolutely perform if the PS3 is only overheat. This is certainly one of the answers to the issue of how to resolve PS3 Yellow Light of Death. If the above technique does not operate, a single of your selections will be taking the console to Sony to have it fixed. Nevertheless, you could need to spend up to $150 in buy to repair the challenge if the guarantee period has ended. You may possibly also need to wait for anything like a month prior to you can get the console back again.
Learn more PS3 recommendations
March 10th, 2011 at 11:36 pm
Hi.. i am not able to find the source code for it…pl z help
March 10th, 2011 at 11:44 pm
where can i get the souce code for sample application..https://github.com/tokudu/PhpMQTTClient/downloads does not not show any downloads!!
March 12th, 2011 at 2:24 pm
Execute this command: git clone git://github.com/tokudu/PhpMQTTClient.git
March 25th, 2011 at 6:15 am
hi.. hay, I want to apply the php sam on CodeIgniter framework, but why can not push into the android?
March 27th, 2011 at 11:58 am
I am currently developing an application on android platform
which allows synchronization of data with the platform
distribution of IP communication services and directory of mobile and
synchronization must be automatically
Is it possible that the server sends notifications to users automatically (without prompting) that have an account without using an operator? (using SMS …)
you have one ideas of push technology?
March 31st, 2011 at 4:59 pm
The world returns to Lexington in April 2011 for the Rolex Kentucky Three-Day Event and the new Ariat Kentucky Reining Cup!
April 6th, 2011 at 6:08 am
How to intercept the Push sent from server? I tried different options but unable to intercept the message. Please provide reply with example.
April 13th, 2011 at 11:55 am
[...] http://tokudu.com/2010/how-to-implement-push-notifications-for-android/comment-page-2/#comment-702 [...]
April 14th, 2011 at 1:55 am
Thanks a lot
Its really an amazing blog.
I was searching for the same thing, you made it very easier to implement push notification in android.
I am using mosquito server instead of rsmb.
Thanks for your all help.
April 14th, 2011 at 1:26 pm
Hi, this tutorial is really great!
But I’ve got a problem… If I change the content of PushService.MQTT_CLIENT_ID from “tokudu” to “blablablabla”, nothing works!
Well… why???
April 19th, 2011 at 5:16 am
Hai, that’s a cool work i test your app with your server, but i want to implement your server side task in asp.net MVC that means in windows, please help me with some guide line. I am novice in MQTT, please forgive me for any unclear specification. Thanks for your time.
April 26th, 2011 at 4:29 am
Not able to send push notification, problem with the SAM_HOST .. Server status is not getting displayed.. I am using a wamp server.. Wht sre the changes need to be done to make it work ?
May 2nd, 2011 at 10:37 pm
Great Post… very helpful for both newbies and advance users
May 3rd, 2011 at 1:23 am
[...] these are complete and any solution would require a lot of custom code. Interestingly, there is a blog post that describes in some detail a possible solution using a lightweight protocol called MQ Telemetry [...]
May 3rd, 2011 at 2:59 pm
Hello, thanks for this tutorial and for the code.
I try to use the PHP code in my server but it didn’t work, so i send an e-mail to the support and they said that if i can’t configure the RSMB by the cPanel then it’s not possible to use it.
I’m doing a work for a class and i want to use this notification so i was wondering if there’s a way i can use your page to send notifications like this: http://tokudu.com/demo/android-push/send_mqtt.php?target=12345&message=test . Using the URL or something similar. When i test the URL it give me the message “MQTT Message to 12345 sent: 12312″ but in the emulator i didn’t receive anything. Is there any workaround like this that i can do to use your page just to send some message in this project? Thank you.
May 4th, 2011 at 1:41 am
I have been trying to post a message to the device from the php page, it shows message “Message Sent” but i cannot see any message on the device. Need HELP!!!!
May 9th, 2011 at 12:27 pm
Google Push or Poll notification…
Push notification 1. Need to register with Google, providing information and details around OTE. 2. The service is currently in beta. 3. Maximum threshold of notifications. 4…….
May 15th, 2011 at 5:10 am
Hello,
Great documentation!
I tried setting up a server and when I run your “android-push” script I get the following error in the error_log:
PHP Fatal error: Cannot redeclare class samconnection in /var/www/html/android-push/SAM/php_sam.php on line 40
Nothing works as a result.
Can there be any bug in the revision ?
Please help,
Thanks!
p.s. PHP 5.3.5
May 15th, 2011 at 11:12 pm
HI,
I am facing
=====================================
Socket error 98 in bind for socket 3
Cannot bind port 1883
Cannot start listener on port 1883
MQTT protocol stopping
Messages sent: 0
Messages received: 0
Uptime: 0 seconds
Maximum heap use: 65490 bytes
Broker stopped
=====================================
I was able to succesfully implement push notification and was able to send notifications to my android phone.
This morning, I was unable to start the broker.
Am I missing something this time ?
Help.
Thanks,
Vinay
May 21st, 2011 at 4:30 pm
[...] How to Implement Push Notifications for Android. [...]
May 29th, 2011 at 12:23 pm
Thank you, this post will make our internal development much easier.
May 30th, 2011 at 12:44 am
Hi thk,
i got the notification icon on my status bar,but unable to open that.will u please give some suggestions on this.
Thanks & regards
mahesh
June 9th, 2011 at 9:40 am
Hi
I have one doubt can i use same id for more than one android device to send message
Thanks
June 13th, 2011 at 1:05 am
how I can use your demo for my app. where i need to change the code.
Help will be appreciated..
Many Thanks in advance.
June 18th, 2011 at 7:27 am
thank you for this stuff
June 20th, 2011 at 9:32 am
Hi!
Thanks a lot for this code, I am successfully using the wmqtt.jar and your in a project of mine.
But I have a little problem, hope you can help me.
When my Android device is connected to a Wifi network I get a “disconnected” from the wmqtt.jar every 0.3seconds and than a reconnect.
Why? And how can I prevent it from doing so?
Thanks a lot!
June 20th, 2011 at 10:09 pm
[...] Start Push-notifications Background-services [...]
June 20th, 2011 at 11:32 pm
Gud Post !!
June 22nd, 2011 at 12:10 pm
Hi
How to get the notification message in Activity and display that message in textview of particular activity .please reply
Thanks in Advance
June 23rd, 2011 at 2:48 am
Hi,
if I’ve x subscribers to this service, is it possible for this technique to push data to just one of the x subscribers?
June 27th, 2011 at 4:56 am
Hi,
It’s a nice article which boosts us..to know more about push notification. But where would the message appears on screen.. I just able to see notification not the text…
June 27th, 2011 at 5:01 am
To see the text message you just stop the service and click the notification. your find one bar and drag it and you can see the messages sent by server..!!!
July 8th, 2011 at 3:40 am
Hello, if i wanted to get push notifications working with java servlets, how would i go about doing this?
July 19th, 2011 at 8:49 pm
hellow Mr… a good tutorial sir… i have tried it on froyo but not running on honeycomb. what should i do Sir?
Thanks
July 29th, 2011 at 5:04 am
Hi,
Thanks for code.
I had installed the app and used your push notification website to send notification but, i does not get push notification.
Please, response me.
Thanks in advance.
August 2nd, 2011 at 3:32 am
Send Push Messages…
iOS APNS (Apple Push Notification Service) is still the only (official) way an app can receive a notification when not running. This holds for iOS 3 and 4 and hasn’t changed in the new iOS 5 (beta)…….
August 12th, 2011 at 11:57 am
Hey ,
I am running sample code for android. My wifi is on.But as i clicked start service button, it doesn’t connect n throw exception..and try connecting again n again but not worked. Please help.. Thanks
August 13th, 2011 at 9:00 pm
[...] On 08.14.11, In Android, by Applerr VN:F [1.9.10_1130]Rating: 0 (from 0 votes)I was following this tutorial for displaying a notification on an Android device. When I ran the application on the [...]
August 24th, 2011 at 12:27 am
Hey ,
I am running sample code for android. .But I’thank that the server is offline Please help . Thanks
August 24th, 2011 at 5:55 pm
i am also see server is offline Please help,and the log show me:MqttException: NULL
August 25th, 2011 at 9:53 am
it doesn’t work, why? forces close, how can i implement the server in jsp/servlet?
September 10th, 2011 at 4:09 pm
The server is down.
I have installed it locally on my machine and tested everything. Worked great! Thank you very much for this.
September 12th, 2011 at 1:08 am
Wow, this is a great tutorial. Thanks for sharing. But i can’t yet tested because “Server status: Offline” on your server sir
September 14th, 2011 at 7:16 am
Sir, can i changes MQTT_CLIENT_ID value? i try it to changes but there is no connection attempt.
Thanks in advance.
September 18th, 2011 at 9:03 am
Are you still supporting this demo? The server is still down. Thanks.
September 20th, 2011 at 6:23 am
Hi,
Server is offline…
Not able to test the service.
Please reply when it can be online again?
September 29th, 2011 at 3:37 am
MQTT server status is offline not sen message
September 30th, 2011 at 9:59 pm
Hi
how can send message to device tokudo server status is offline
September 30th, 2011 at 11:07 pm
Server status offline..Message not received on mobile.
September 30th, 2011 at 11:08 pm
kindly make it working asap
thanks
October 5th, 2011 at 1:55 am
Thank you very much for this great solution. I managed to even make my own servers (Ubuntu 10.04 and CentOS 5 ) working with “mosquitto”.
Keep up the good work!
October 5th, 2011 at 6:09 am
One remark for those that want to modify some settings:
The static field MQTT_CLIENT_ID should not be set for a value longer than 6 characters, otherwise you will get an error: “MqttException: MQIsdp ClientId > 23 bytes”
October 6th, 2011 at 7:54 pm
Hi,
Server is offline…
Not able to test the service.
Please reply when it can be online again?
October 12th, 2011 at 7:04 am
Hi thk !
need your attention please for following link:
http://www.openmobilealliance.org/tech/affiliates/wap/wap-247-pap-20010429-a.pdf
can we implement that protocol for push notification today?
Regards,
Shaman Virk
October 13th, 2011 at 11:15 pm
hi,
my app needs to be notified every minute but also sometimes after every 10 to 30 to 1 hr. C2DM is not suited for my App as it will black list the server for notifying frequently, did this idea will support me for this problem?
October 18th, 2011 at 1:57 am
Hi,
Server is offline…
Not able to test the push notification service on android phone.
Please reply ?
Thanks,
Manoj Jangra
October 19th, 2011 at 2:54 am
server status in offline how can i make it online for testing android push notifcation app
October 19th, 2011 at 10:48 am
Thanks , I’ve just been looking for information approximately this topic for a long time and yours is the best I have came upon so far. But, what about the conclusion? Are you certain in regards to the supply?
October 19th, 2011 at 11:55 pm
Feature Matrix…
Html 5 \\ Android \\ Geolocation \\ X …
October 20th, 2011 at 2:25 am
server status offline
,,is thr any other wat to test this android push notification
November 1st, 2011 at 4:49 am
Excellent post. But unfortunately server is offline.
November 2nd, 2011 at 5:58 pm
Sorry about that guys. The server should be back online now.
November 3rd, 2011 at 6:04 am
[...] [...]
November 7th, 2011 at 11:40 pm
well the server is online now but i m not getting the message or notification on my emulator,,,i hav entered the target device and then sent the message from the server but nothing appears on my emulator
,,,also i hav started the service on emulator,,, help me out
November 7th, 2011 at 11:51 pm
it is working on the device,,but dont kw y it didnt wrk on emulator,,,thnks 4 dis nyc post
November 8th, 2011 at 12:18 am
very helpful code…
gr8 learing from it..
recently i have used it in one of my application…
it is runniing fine..
i m in testing phase…
can you suggest one or two test case for this kind of notification app..
like data length that supported by notification app?
November 8th, 2011 at 1:17 am
But a persistent service is running in the background that it eating up the battery life,,and if we stop that service then no message that reaches the android client,,,,and even we on the service again the message is not stored and is lost,,,,
November 9th, 2011 at 11:49 pm
Hello, I wonder about the limitation of MQTT.
How many clients can use?
Don’t anybody have SPEC. of MQTT?
November 10th, 2011 at 5:15 pm
Get your free porn and awesome smut reviews here.
November 14th, 2011 at 1:47 am
Hi;
I built the apk from your code and installed it on my Xperia X10. started the app
and clicked on ‘Start Push Service’ button.
in the portal http://tokudu.com/demo/android-push/ , I entered the device ID and message text. clicked on Send Push Message.
But I did not get any notification. I tried several times but no use. please can you help on this.
Thanks
Venkat
November 14th, 2011 at 3:11 am
the demo which I download,there are some error exist in the project,but I see the source,I didn’t find any error,why?
November 17th, 2011 at 7:57 pm
Hi,
i have some question.
if i try to run code from localhost.
and the target is android what ip host should be?
127.0.0.1 or 192.168.2.1
and what port number should be?
1883 or xampp localhost port 3306
actually, I try both of that but it didn’t work at all
and i have to edit index.php and send_mqtt.php only?
there are other file i have to edit?
and how can i fix this?
Use of undefined constant SAM_HOST – assumed ‘SAM_HOST’
Use of undefined constant SAM_PORT – assumed ‘SAM_PORT’
thanks in advance
ps. i am a not an expert for programming server side
ps2. sorry about my english grammar
November 21st, 2011 at 12:46 am
Dear All,
Thanks for Anton,
I had tried the MQTT server and Client.
The following is my recap for this demo,
1.Any question for 1833 ,please down the MQTT from IBM first. then keep the MQTT on(Dont close the windows)
2. Use Wifi connection replace of 3g connection, then make sure your server and wifi route in same domain,and can be ping each other.
3. in Android’s program, change the “MQTT_HOST” IPto your mqtt server.
4.Try sent message again…..
Have a good one…
Sam
November 28th, 2011 at 11:07 pm
How to add custom sound for this push notification. We implemented this push notification method in our apps. Its work fine. We need to add custom sound for this push notification alerts.
Thanks in advance
December 4th, 2011 at 11:22 pm
I quite sympathize with your take on this topic. Thanks for bringing this to our attention. Do you have any other essays like this one?
December 11th, 2011 at 7:42 am
Hi check with u why the target requires topic://
December 15th, 2011 at 10:13 pm
hello anton why push notification cannot be received in Samsung Galaxy i have installed the app
December 17th, 2011 at 5:58 am
Mobile Devices…
Andriod Some links for notifications:…
January 2nd, 2012 at 7:48 pm
Usually I don’t read post on blogs, however I would like to say that this write-up very compelled me to take a look at and do it! Your writing taste has been surprised me. Thanks, quite great post.
January 3rd, 2012 at 5:53 pm
I am looking for a push solution for an Android application and am very excited to see ho well this performs… I am fairly new to Android development and have a test phone but it does not have a sim card. When I run your application I am not getting a device target ID. is this because I do not have a sim card? If not, is there anything else that you can think might be causing this?
Any help would be greatly appreciated. Thanks in advance.
January 6th, 2012 at 6:26 am
[...] 原文地址:http://tokudu.com/2010/how-to-implement-push-notifications-for-android/ [...]
January 9th, 2012 at 2:45 pm
thank you very much you are awesome dude
January 15th, 2012 at 1:06 pm
[...] How to Implement Push Notifications for Android Not everyone has an SMS plan and you don’t want your users getting charged by 3rd party for using your app. [...]
January 19th, 2012 at 8:16 pm
That is why I had to give up my android for an iphone
January 19th, 2012 at 8:17 pm
I use the android all the time and this helped to know how to set up push notifications. Thank you.
January 20th, 2012 at 4:51 pm
Been playing with your code for a project I’m tinkering it. Did find one problem with it thought. It seems that the connect will Force Close the app if the broker server is unreachable. It seems that the wmqtt.jar does not allow a timeout less than 10 seconds. Haven’t been able to find the source code to the jar. Using jad to decompile is no help (other than finding the 10 second timeout code)
Any ideas if the source is available? I’m trying googling for it with no luck.
Thanks!
Dan
January 31st, 2012 at 5:00 am
I read the complete post but as I’m new quite new to android development, I was unable to implement it perfectly.
When I run the app, “Start Push Service button is automatically pressed”. So if I push a message from `http://tokudu.com/demo/android-push/` to device, it doesn’t appear on device.
Please help.
Thanks in advance.
Gaurav.
January 31st, 2012 at 5:08 am
My start button was already pressed so I wrote the code for on Start button click in onCreate() method.
Then I got following log
Creating service
Opened log at /mnt/sdcard/LOG/push.log-20120126-070750
Handling crashed service…
Starting service…
Connecting…
threadid=3: reacting to signal 3
Wrote stack traces to ‘/data/anr/traces.txt’
MqttException: NULL
Rescheduling connection in 10000ms.
Service started with intent=Intent { act=tokudu.START cmp=com.tokudu.demo/.PushService }
Starting service…
Attempt to start connection that is already active
Connectivity changed: connected=true
Reconnecting…
Connecting…
threadid=3: reacting to signal 3
Wrote stack traces to ‘/data/anr/traces.txt’
Please help. Or suggest what am I doing wrong… please reply…
January 31st, 2012 at 5:15 am
Also, in manifest file of source code,
is not mentioned. So it was giving fileNotFoundException as it was unable to create the log file.
So I added the above permission to manifest file.
Is it okay?
February 1st, 2012 at 12:17 pm
i wanna put this code in my own domain and i can’t find how to do that
when i do that this message appear
Server status:
Warning: fsockopen() [function.fsockopen]: fsockopen() functionality if not on by default; please purchase this option by contacting zymic.com in /www/clanteam.com/p/u/s/pushmsg/htdocs/SAM/MQTT/sam_mqtt.php on line 640
Offline
i wanna know what i change to do that ?
February 2nd, 2012 at 2:00 am
hi,
can we send push notifications to more than one device at a time with mqtt in android ?.if yes please tell me how.
February 2nd, 2012 at 6:42 am
$result = $conn->connect(SAM_MQTT, array(SAM_HOST => ’127.0.0.1′, SAM_PORT => 1883));
i must change the sam host and port ??
February 2nd, 2012 at 2:05 pm
i wanna know which port i use ?!!!
the same port in the code
February 3rd, 2012 at 12:13 am
how to send a push notifications to multiple users by single query in android?
February 3rd, 2012 at 4:52 am
i wanna ask about port 1883 can i use port 80 instead of port 1883