FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Open Source
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
TABLE OF CONTENTS
May 18, 2009

The Android 1.5 Developer Experience

(Page 2 of 2)

Writing an AppWidget

The AppWidget API is perhaps the most exciting new feature for 1.5 developers due to the way it can be used to expose larger applications in a very small viewport on the Android desktop. Similar to Microsoft Windows desktop widgets, Android widgets live on the desktop and can be mounted and relocated on any of the three Android desktop screens. The OS comes stocked with an Analog Clock, Calendar, Music, Picture Frame and Search widgets, and the Android Marketplace has rapidly expanded with many others including widgets for monitoring battery, internal and SD storage capacity, messaging and many more.

Technically, AppWidgets can be embedded in other applications besides the Android home/desktop, reminding me of the days when Microsoft introduced the concept of OLE (Object Linking and Embedding) to the PC desktop.

Writing a AppWidget is quite easy, especially for seasoned Android developers. The main coding concepts to remember are the XML AppWidget layout metadata and its conduit of communication via the BroadcastReceiver intent. Each of these are defined and stored like other application metadata such as name, icon, version, permissions and more in the Android project's AndroidManifest.xml file.

Once defined, extending a custom class from the AppWidgetProvider helper class helps manage the various broadcast events and managing whatever update and error handling within that class makes widget construction almost too easy. AppWidget is an excellent, easy-to-follow tutorial (accompanied by full source code), written by Android Developer Challenge winner and relatively new Google employee Jeff Sharkey. Additional AppWidget details can be found in the Android Dev Guide.

Using this simple framework, I wrote a rudimentary widget to post an XMPP message to my Identi.ca account that then replicates the post to my Twitter account. Although several Twitter clients are currently available in the Android Marketplace (the best still being Twidroid), I prefer quick and lightweight. While most widgets offer a window into a much larger back-end application, others like mine perform a simple service. The advantageous design aspect behind widgets is the fact that they can support this wide spectrum of usage scenarios.

Gaining Momentum

While still quite a ways behind the iPhone in terms of elegance and ease of use, the Android platform is rapidly gaining ground and, in certain technical categories, surpassing what the iPhone 3G running the 2.x version OS can do. When I demo'd the new Android 1.5 features to a co-worker who is an ardent iPhone fan, he was pleased to see the innovations the Android team had injected into their OS. Why was he pleased? Because these improvements will drive Apple to further innovation on the platform, prompting a mobile arms war between the two platforms that will ultimately benefit consumers with amazing capabilities in the palm of their hand.

Even so, the new 1.5 additions supply developers with powerful, exciting possibilities. Looking over some of my favorite Android 1.0 applications, I foresee programs like the TTS Translator program leveraging the android.speech RecognizerIntenet to allow near real-time spoken word language translation. My favorite Twitter (and Identi.ca/Laconi.ca) client on Android, Twidroid, will hopefully leverage the Widget API in a future release to expose portions of its program to the desktop. In the meantime, I have created my own simple XMPP widget for immediate access, one click quick posts to my Identi.ca account that then propagates my Tweet to my Twitter account. Considering that this hack took me less than an hour to design, code, package and install on my Android Dev Phone, the power and potential of the Android platform is really coming into focus. I can't wait to see what's in store for the next major release of the Android OS.

Previous Page | 1 Introduction | 2 Writing an AppWidget
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK