<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>

<channel>
	<title>Tokudu - The THK Chronicles</title>
	<atom:link href="http://tokudu.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://tokudu.com</link>
	<description></description>
	<pubDate>Sun, 29 Aug 2010 17:52:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Burning Man Haircut</title>
		<link>http://tokudu.com/2010/burning-man-haircut/</link>
		<comments>http://tokudu.com/2010/burning-man-haircut/#comments</comments>
		<pubDate>Sun, 29 Aug 2010 17:52:26 +0000</pubDate>
		<dc:creator>thk</dc:creator>
		
		<category><![CDATA[It Happens]]></category>

		<guid isPermaLink="false">http://tokudu.com/?p=742</guid>
		<description><![CDATA[Burning Man is a desperate time, which requires some desperate measures. And according to my cousin Mike, it&#8217;s also a time to get a funky haircut. What is a better place to get it than Haight and Ashbury? Me and mike went there yesterday searching for some random clothes and a decent hair salon. Unfortunately, [...]]]></description>
			<content:encoded><![CDATA[<p>Burning Man is a desperate time, which requires some desperate measures. And according to my cousin Mike, it&#8217;s also a time to get a funky haircut. What is a better place to get it than <a href="http://en.wikipedia.org/wiki/Haight-Ashbury" target="_blank">Haight and Ashbury</a>? Me and mike went there yesterday searching for some random clothes and a decent hair salon. Unfortunately, the one we found was super jammed, but the guy there referred us to his boyfriend at a salon in Hayes Valley called <a href="http://www.yelp.com/biz/blo-salon-san-francisco" target="_blank">Blo</a>. Well, here is the result:</p>
<p style="text-align: center; "><a href="http://tokudu.com/wp-content/uploads/2010/08/img_20100829_101757.jpg"><img class="aligncenter size-medium wp-image-745" title="img_20100829_101757" src="http://tokudu.com/wp-content/uploads/2010/08/img_20100829_101757-300x260.jpg" alt="img_20100829_101757" width="300" height="260" /></a><a href="http://tokudu.com/wp-content/uploads/2010/08/img_20100829_101750.jpg"><img class="aligncenter size-medium wp-image-744" title="img_20100829_101750" src="http://tokudu.com/wp-content/uploads/2010/08/img_20100829_101750-300x266.jpg" alt="img_20100829_101750" width="300" height="266" /></a><a href="http://tokudu.com/wp-content/uploads/2010/08/img_20100829_101738.jpg"><img class="size-medium wp-image-743  aligncenter" title="img_20100829_101738" src="http://tokudu.com/wp-content/uploads/2010/08/img_20100829_101738-300x282.jpg" alt="img_20100829_101738" width="300" height="282" /></a></p>
<p>If you like the result, the stylist&#8217;s name is Dustin. Tell him that Anton and Mike referred him (the guys who got crazy Burning Man lines).</p>
<p>The scariest thought right now is how I&#8217;m gonna go to work after Burning Man&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://tokudu.com/2010/burning-man-haircut/feed/</wfw:commentRss>
		</item>
		<item>
		<title>White Panda mixes Eminem</title>
		<link>http://tokudu.com/2010/white-panda-mixes-eminem/</link>
		<comments>http://tokudu.com/2010/white-panda-mixes-eminem/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 23:25:33 +0000</pubDate>
		<dc:creator>thk</dc:creator>
		
		<category><![CDATA[Music]]></category>

		<category><![CDATA[enimen]]></category>

		<category><![CDATA[remix]]></category>

		<category><![CDATA[white panda]]></category>

		<guid isPermaLink="false">http://tokudu.com/?p=740</guid>
		<description><![CDATA[I don&#8217;t know what it is about Enimen, but it doesn&#8217;t matter matter what style his songs are mixed in, it always sounds awesome. And that&#8217;s especially true, when it&#8217;s mixed by someone as talented as White Panda. Here is a recent remix from them: of Heads Will Roll:

]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">I don&#8217;t know what it is about Enimen, but it doesn&#8217;t matter matter what style his songs are mixed in, it always sounds awesome. And that&#8217;s especially true, when it&#8217;s mixed by someone as talented as White Panda. Here is a recent remix from them: of Heads Will Roll:</p>
<p style="text-align: center;"><object width="480" height="385" data="http://www.youtube.com/v/ika8snMJntc&amp;hl=en_US&amp;fs=1" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/ika8snMJntc&amp;hl=en_US&amp;fs=1" /><param name="allowfullscreen" value="true" /></object></p>
]]></content:encoded>
			<wfw:commentRss>http://tokudu.com/2010/white-panda-mixes-eminem/feed/</wfw:commentRss>
		</item>
		<item>
		<title>My New Loaded Dervish Longboard</title>
		<link>http://tokudu.com/2010/my-new-loaded-dervish-longboard/</link>
		<comments>http://tokudu.com/2010/my-new-loaded-dervish-longboard/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 01:17:15 +0000</pubDate>
		<dc:creator>thk</dc:creator>
		
		<category><![CDATA[Skating & Boarding]]></category>

		<category><![CDATA[bigzigs]]></category>

		<category><![CDATA[dervish]]></category>

		<category><![CDATA[loaded]]></category>

		<category><![CDATA[longboarding]]></category>

		<category><![CDATA[skateboarding]]></category>

		<guid isPermaLink="false">http://tokudu.com/?p=722</guid>
		<description><![CDATA[
So, I moved to San Francisco 4 days ago to start my new job. When I was packing up my things, I just had too much stuff. As a result, I decided to sell a whole bunch of my things to reduce the cost of moving. Obviously, among the first victims was my longboard. My [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-medium wp-image-723 alignright" title="img_20100710_172724" src="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172724-300x225.jpg" alt="img_20100710_172724" width="300" height="225" /></p>
<p>So, I moved to San Francisco 4 days ago to start my new job. When I was packing up my things, I just had too much stuff. As a result, I decided to sell a whole bunch of my things to reduce the cost of moving. Obviously, among the first victims was my longboard. <a href="http://tokudu.com/2009/new-gumballs-for-my-longboard/" target="_blank">My baby</a> served me well for the past year and a half, and I really didn&#8217;t want to give it up. However, it was just not meant to be. There was no chance I would fit it in one of my suitcases and shipping it would be just too expensive. So I sold it to a nice kid in Toronto with a thought that I would buy an even better board, when I get to SF.</p>
<p>Once I sold the board, I started looking around for the hip things on the market. At first, I settled on getting the <a href="http://www.originalskateboards.com/longboards/apex-longboard" target="_blank">Apex 37</a> from the Original Skateboards. Originals have become quite popular in the past couple of years, and it seemed like a great choice. The Original boards are famous for the their spring-based trucks that are amazing carving machines. As a result, they are not really made for bombing hills, which is kinda what I was looking for. Apex 37 is a great all-around board, but it can get quite wobbly at  higher speeds.</p>
<p>Moreover, for the past couple of months the Apex 37 and Apex 34 have been out of stock. People at Original&#8217;s <a href="http://www.facebook.com/OriginalSkateboards" target="_blank">Facebook</a> page claimed that it might take a few months until the boards come back in stock. This was no option for me, as I really didn&#8217;t want to spend a couple of months without a board.</p>
<p><span id="more-722"></span></p>
<p>I decided to take a walk to one of the best skate shops in San Francisco - <a href="http://www.skatesonhaight.com/" target="_blank">Skates on Haight</a> and see what they have to offer. There I talked to <a href="http://compass.ups.com/customerstories/article.aspx?id=3315" target="_blank">Carol Sloan</a>, the owner, who is probably one of the most knowledgeable people in the skating business that I have ever talked to. She told me that the delays with shipment of Original&#8217;s is probably due to a recent strike of the Chinese manufactures. Moreover, I talked to her about another board that I was considering - the <a href="http://www.loadedboards.com/boards/dervish.html" target="_blank">Loaded Dervish</a>. She said that it was a great choice for my needs and helped pick out a great setup, which cost me around 321$ with all taxes included:</p>
<ul>
<li>Loaded Dervish Flex 1</li>
<li>Abec 11 BigZigs Lemon 75mm/83a</li>
<li>Paris 180mm Crimson Slide</li>
</ul>
<p>I definitely recommend anyone, who is looking into buy a board in San Francisco, to check out Skates on Haight. People there are great.</p>
<p>Anyways, enough of my rant. Let&#8217;s check out the pictures of my new baby (click for large images):</p>
<p><a href="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172732.jpg"><img class="size-medium wp-image-724 alignleft" title="img_20100710_172732" src="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172732-300x225.jpg" alt="img_20100710_172732" width="300" height="225" /></a><a href="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172738.jpg"><img class="size-medium wp-image-725 alignright" title="img_20100710_172738" src="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172738-300x225.jpg" alt="img_20100710_172738" width="300" height="225" /></a><a href="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172753.jpg"><img class="size-medium wp-image-726 alignleft" title="img_20100710_172753" src="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172753-300x225.jpg" alt="img_20100710_172753" width="300" height="225" /></a><a href="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172803.jpg"><img class="size-medium wp-image-727 alignright" title="img_20100710_172803" src="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172803-300x225.jpg" alt="img_20100710_172803" width="300" height="225" /></a><a href="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172822.jpg"><br />
</a><a href="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172834.jpg"><img class="size-medium wp-image-729 alignleft" title="img_20100710_172834" src="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172834-300x225.jpg" alt="img_20100710_172834" width="300" height="225" /></a></p>
<p><a href="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172843.jpg"><img class="size-medium wp-image-730 alignright" title="img_20100710_172843" src="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172843-300x225.jpg" alt="img_20100710_172843" width="300" height="225" /></a><a href="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172857.jpg"><img class="size-medium wp-image-731 alignleft" title="img_20100710_172857" src="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172857-300x225.jpg" alt="img_20100710_172857" width="300" height="225" /></a><a href="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172916.jpg"><img class="size-medium wp-image-732 alignleft" title="img_20100710_172916" src="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172916-225x300.jpg" alt="img_20100710_172916" width="225" height="300" /></a><a href="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172923.jpg"><img class="size-medium wp-image-733 alignright" title="img_20100710_172923" src="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172923-225x300.jpg" alt="img_20100710_172923" width="225" height="300" /></a></p>
<p><a href="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172822.jpg"><img class="size-medium wp-image-728 alignleft" title="img_20100710_172822" src="http://tokudu.com/wp-content/uploads/2010/07/img_20100710_172822-225x300.jpg" alt="img_20100710_172822" width="225" height="300" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://tokudu.com/2010/my-new-loaded-dervish-longboard/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Android: Checkable Linear Layout</title>
		<link>http://tokudu.com/2010/android-checkable-linear-layout/</link>
		<comments>http://tokudu.com/2010/android-checkable-linear-layout/#comments</comments>
		<pubDate>Sun, 23 May 2010 00:56:59 +0000</pubDate>
		<dc:creator>thk</dc:creator>
		
		<category><![CDATA[Android]]></category>

		<category><![CDATA[Nerdgasms]]></category>

		<category><![CDATA[checkable]]></category>

		<category><![CDATA[layout]]></category>

		<category><![CDATA[linear]]></category>

		<category><![CDATA[linearlayout]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[textview]]></category>

		<guid isPermaLink="false">http://tokudu.com/?p=711</guid>
		<description><![CDATA[A common thing you might want to do, when you developing an Android app, is to have a ListView of checkable items. For instance, you might want to have a functionality in your app to share something with a bunch of people, who you would like to select from a list of contacts. For common [...]]]></description>
			<content:encoded><![CDATA[<p>A common thing you might want to do, when you developing an Android app, is to have a <a href="http://developer.android.com/intl/fr/reference/android/widget/ListView.html" target="_blank">ListView</a> of checkable items. For instance, you might want to have a functionality in your app to share something with a bunch of people, who you would like to select from a list of contacts. For common choice for this task is to use a <a href="http://developer.android.com/intl/fr/reference/android/widget/CheckedTextView.html" target="_blank">CheckedTextView</a> and the <em><strong>android:choiceMode </strong><span style="font-style: normal;">parameter of the ListView</span></em>. This extension of a regular <a href="http://developer.android.com/intl/fr/reference/android/widget/TextView.html" target="_blank">TextView</a> has a check box on the right, so that it can be selected.</p>
<p>However, there is a limitation here. <a href="http://developer.android.com/intl/fr/reference/android/widget/CheckedTextView.html" target="_blank">CheckedTextView</a> has to be the root element of the layout that you use for your items. So if you wish to display multiple things (user name and email) for each item  by using a <a href="http://developer.android.com/intl/fr/reference/android/widget/LinearLayout.html" target="_blank">LinearLayout</a>, you are out of luck. The reason for this limitation is that he root item must implement the <a href="http://developer.android.com/intl/fr/reference/android/widget/Checkable.html" target="_blank">Checkable</a> interface and the <a href="http://developer.android.com/intl/fr/reference/android/widget/LinearLayout.html" target="_blank">LinearLayout</a> doesn&#8217;t implement it.</p>
<p>The solution here is to&#8230;</p>
<p><span id="more-711"></span></p>
<p>&#8230;override  <a href="http://developer.android.com/intl/fr/reference/android/widget/LinearLayout.html" target="_blank">LinearLayout</a> to implement the required interface. I present to you <strong><em>CheckableLinearLayout</em></strong>. Upon inflation it searches through its children for the <a href="http://developer.android.com/intl/fr/reference/android/widget/CheckedTextView.html" target="_blank">CheckedTextView</a>, and then forwards any calls required by the Checkable interfaces to that component:<br />
<script src="http://gist.github.com/410479.js?file=CheckableLinearLayout.java"></script> Now, we can use that component in the layout file for our list items:   <script src="http://gist.github.com/410495.js?file=list_entry_contacts.xml"></script><br />
Make sure you set in your <strong><em>ListView</em></strong>&#8217;s XML: <em>android:choiceMode=&#8221;multipleChoice&#8221;</em>.</p>
<p>This class is now a part of my Android library <a href="http://github.com/tokudu/begemot" target="_blank">Begemot</a>.</p>
<p>Follow me <a href="http://twitter.com/tokudu" target="_blank">@tokudu</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tokudu.com/2010/android-checkable-linear-layout/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to Implement Push Notifications for Android</title>
		<link>http://tokudu.com/2010/how-to-implement-push-notifications-for-android/</link>
		<comments>http://tokudu.com/2010/how-to-implement-push-notifications-for-android/#comments</comments>
		<pubDate>Fri, 14 May 2010 06:17:43 +0000</pubDate>
		<dc:creator>thk</dc:creator>
		
		<category><![CDATA[Android]]></category>

		<category><![CDATA[Nerdgasms]]></category>

		<category><![CDATA[mobile]]></category>

		<category><![CDATA[mqtt]]></category>

		<category><![CDATA[notifications]]></category>

		<category><![CDATA[push]]></category>

		<category><![CDATA[tcp]]></category>

		<guid isPermaLink="false">http://tokudu.com/?p=681</guid>
		<description><![CDATA[
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 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://tokudu.com/wp-content/uploads/2010/05/android-push.png"><img class="size-full wp-image-684 alignright" title="android-push" src="http://tokudu.com/wp-content/uploads/2010/05/android-push.png" alt="android-push" width="256" height="500" /></a></p>
<p>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&#8217;s go over how it all started.</p>
<p><strong>Introduction</strong></p>
<p style="text-align: left;">It&#8217;s been around 4 months now since I&#8217;ve started developing apps on the Android platform. It began with me scoring a free Nexus One phone at one of the <a href="https://sites.google.com/site/androiddevlabs/register" target="_blank">Android Developer Labs</a>.  Obviously, I couldn&#8217;t resist trying to hack around with some code, so I downloaded the SDK and dove in. I guess in some sense, that&#8217;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.</p>
<p>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.</p>
<p>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&#8217;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&#8217;s go over the list:</p>
<ul>
<li><strong>Poll?</strong> The name obviously tells you that it&#8217;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.</li>
</ul>
<div style="margin-left:40px"><span style="text-decoration: underline;">Advantages</span>: easy to implement. no cost solution</div>
<div style="margin-left:40px"><span style="text-decoration: underline;">Disadvantages</span>: Obviously, you will never be actually real-time. If you polling interval is 30 min, you can get a message that is 29 minutes and 59 seconds late. Moreover, polling more often than every 15-30 min will kill your battery pretty quickly: <a href="https://labs.ericsson.com/apis/mobile-java-push/blog/save-device-battery-mobile-java-push">https://labs.ericsson.com/apis/mobile-java-push/blog/save-device-battery-mobile-java-push</a></div>
<ul>
<li><strong>SMS </strong>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.</li>
</ul>
<div style="margin-left:40px"><span style="text-decoration: underline;">Advantages</span>: easy to implement. Fully real-time updates. Known drop-in solutions exist such as one provided by Ericsson  Labs: <a href="https://labs.ericsson.com/apis/mobile-java-push/">https://labs.ericsson.com/apis/mobile-java-push/</a></div>
<div style="margin-left:40px"><span style="text-decoration: underline;">Disadvantages</span>: Can be costly to you and the user. There are only a few services that allow you send around free SMS and even those are often limited to North America. If you want to have a reliable SMS-based service that is available worldwide, you will likely need to pay. Similar goes for the users. Not everyone has an SMS plan and you don&#8217;t want your users getting charged by 3rd party for using your app.</div>
<ul>
<li><strong>Persistent TCP/IP </strong>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.</li>
</ul>
<div style="margin-left:40px"><span style="text-decoration: underline;">Advantages</span>: Fully real-time updates.</div>
<div style="margin-left:40px"><span style="text-decoration: underline;">Disadvantages</span>: Hard to implement a reliable service on both the phone and the server side. The Android OS is known to be able to kill services when it&#8217;s running low on memory, so your notifications service can easily disappear. What happens when your phone goes to sleep? Some people complain about battery life issues related to maintaining an active connection.</div>
<p>The first two methods have significant disadvantages that we cannot do anything about. However, the third method&#8217;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&#8217;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.</p>
<p><strong>Persistent TCP/IP</strong></p>
<p>After more Googling around I was able to come across three reasonable efforts to implement push notifications using a persistent TCP/IP connection:</p>
<ul>
<li><em><strong>Josh Guilfoyl</strong></em><strong>e</strong> talks about how to create a most-idle TCP/IP connection with a long keep-alive timer based on the <a href="http://developer.android.com/intl/fr/reference/android/app/AlarmManager.html" target="_blank">AlarmManager</a>. He provides some really cool sample code with a service that runs in the background and makes connections. <a href="http://devtcg.blogspot.com/2009/01/push-services-implementing-persistent.html">http://devtcg.blogspot.com/2009/01/push-services-implementing-persistent.html</a></li>
<li><em><strong>Dave Rea</strong></em> recently started the Deacon project, which is aimed at developing a 3rd party library for Android push notifications using <a href="http://en.wikipedia.org/wiki/Comet_(programming)" target="_blank">comet technology</a> based on <a href="http://www.meteorserver.org/" target="_blank">the Meteor server</a>. The project is still in a very early stage (at the time of this post), but looks quite promising. <a href="http://deacon.daverea.com/">http://deacon.daverea.com/</a></li>
<li><em><strong>Dale Lane</strong></em> had done a number of presentations, where he talked about using the IBM developed <a href="http://mqtt.org/" target="_blank">MQTT</a> protocol for implementing Android push notifications. He also provides some really useful sample Android code. <a href="http://dalelane.co.uk/blog/?p=938">http://dalelane.co.uk/blog/?p=938</a></li>
</ul>
<p>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&#8217;s <a href="http://code.google.com/p/android-random/source/browse/#svn/trunk/TestKeepAlive" target="_blank">TestKeepAlive</a> project and Dale Lane&#8217;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&#8217;s get to the good stuff.</p>
<p><strong>My Idea</strong></p>
<p>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&#8217;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&#8217;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&#8217;s take a quick look at the man page:</p>
<p><em><strong>mqtt</strong> 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.</em></p>
<p>Did you see the part about &#8216;low power&#8217;? 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&#8217;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.</p>
<p>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.</p>
<p><strong>Architecture</strong></p>
<p>In my example, I utilize a PHP script as a server. This uses the Simple Asynchronous Messaging  library (see project SAM <a href="http://project-sam.awardspace.com/">http://project-sam.awardspace.com/</a>) to publish MQTT messages to the broker on which I host on my server. Let&#8217;s have a look at the overall system diagram:</p>
<p style="text-align: center; "><a href="http://tokudu.com/wp-content/uploads/2010/05/system_diagram.png"><img class="size-full wp-image-687  aligncenter" title="system_diagram" src="http://tokudu.com/wp-content/uploads/2010/05/system_diagram.png" alt="system_diagram" width="500" height="445" /></a></p>
<p style="text-align: left; "><strong>wmqtt.jar </strong>is a simple drop-in implementation of MQTT protocol provided by IBM. It can be downloaded from <a href="http://www-01.ibm.com/support/docview.wss?rs=171&amp;uid=swg24006006">http://www-01.ibm.com/support/docview.wss?rs=171&amp;uid=swg24006006</a>. 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.</p>
<p style="text-align: left; "><strong>Really Small Message Broker (RSMB)</strong> is a simple MQTT broker also provided by IBM <a href="http://www.alphaworks.ibm.com/tech/rsmb">http://www.alphaworks.ibm.com/tech/rsmb</a>. 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 <a href="http://mosquitto.atchoo.org/">http://mosquitto.atchoo.org/</a>.</p>
<p style="text-align: left; "><strong>SAM</strong> is a drop-in PHP library for MQTT and other stuff. You can either get it as PECL extension or download the source online <a href="http://pecl.php.net/package/sam/download/0.2.0">http://pecl.php.net/package/sam/download/0.2.0</a>.</p>
<p style="text-align: left; "><strong>send_mqtt.php</strong> is a simple PHP script that accepts messages over POST and uses SAM to pass-on messages to the broker.</p>
<p><strong>Sample Code and Demo</strong></p>
<p><a href="http://tokudu.com/wp-content/uploads/2010/05/push-app.png"><img class="alignleft size-full wp-image-694" title="push-app" src="http://tokudu.com/wp-content/uploads/2010/05/push-app.png" alt="push-app" width="261" height="500" /></a></p>
<p>The goal of my work on push notifications was to develop a working demo, which is what all other examples out there lack. I&#8217;m happy to say that I accomplished my objective. You can download the sample android app on <a href=" http://github.com/tokudu/AndroidPushNotificationsDemo" target="_blank">GitHub</a>.</p>
<p>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 <a href="http://tokudu.com/demo/android-push/">http://tokudu.com/demo/android-push/</a> and enter the device ID in the first text box and enter the message text in the textarea below. Press &#8220;Send Push Message&#8221; and you should get a notification on your phone. It&#8217;s as easy as that.</p>
<p>You can see the source code for <strong>andoid-push</strong> in <a href="http://github.com/tokudu/PhpMQTTClient" target="_blank">this GitHub</a> project. It contains the aforementioned <strong>send_mqtt.php</strong> script.</p>
<p><em>If you didn&#8217;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&#8217;s the case, please post a comment and I will look into it bringing the broker back up.</em></p>
<p><strong>Final Thoughts and Comments</strong></p>
<p>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&#8217;s probably a good idea to encrypt them. Alternatively, you could write your own broker and introduce some sort of authentication to MQTT.</p>
<p>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.</p>
<p>Also let me know if you find any bad bugs. Good luck testing!</p>
<p>Anton Lopyrev</p>
<p>Follow me on twitter <a href="http://twitter.com/tokudu" target="_blank">@tokudu</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tokudu.com/2010/how-to-implement-push-notifications-for-android/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
