10EDIT     ION          th                  TEN               Xom D                c         E                         ED ...
published by:      Services and Tools for All Mobile Platforms            Enough Software GmbH + Co. KG                   ...
Mobile Developer’s GuideTable of Contents1	Introduction4	  An Overview Of Application Platforms4	  Native Applications6	  ...
27	 Programming BlackBerry Apps28	Prerequisites30	 Coding Your Application30	Services31	Testing32	Porting33	Signing33	Dist...
62	 Programming Qt Apps64	Prerequisites64	 Creating Your Application66	Testing67	Packaging67	Signing68	Distribution71	 Pro...
95	 Programming Mobile Widgets96	 Widget Characteristics100	Prerequisites100	 Writing Your Code102	Testing104	Signing104	D...
139	   Implementing Rich Media139	   Streaming vs. Local Storage141	   Progressive Download141	   Media Converters142	   I...
153	 Implementing Haptic Vibration157	 Basic Vibration Control on Android158	 Extending Basic Vibration Control159	 Implem...
173	Monetization174	 Pay Per Download177	 In-App Payment178	 Mobile Advertising179	 Revenue Sharing179	 Indirect Sales180	...
IntroductionWelcome to the 10th anniversary edition of our Mobile Develop-ers Guide To The Galaxy! We introduced the first...
mobile browsers, Tizen released a preview SDK, HP changed itsmind and announced webOS would continue as an Open Sourceproj...
An Overview Of ApplicationPlatformsThere is a wide selection of platforms with which you can realizeyour mobile vision. Th...
Platform       Language(s)        RemarksAndroid                           Open Source OS (based on Linux)               J...
Java ME (J2ME)Around 70% of all featurephones worldwide support the mobileJava standard (Java ME formerly known as J2ME), ...
Flash is favored by many designers, since they know the toolsalready and it can be used to create engaging, powerful useri...
make this approach challenging. Some browsers are very power-ful and support CSS as well as JavaScript; others are less so...
Environment   Language(s)       Remarks                                Standard web technology basedSymbian               ...
SMS Text MessagingAlmost everybody who has a mobile phone is also texting. Tex-ting limits interactions to less than 160 c...
Programming Android AppsThe Android platform is developed by the Open Handset Allianceled by Google and has been publicly ...
set-top boxes, desktop phones and car entertainment systems.Some non-Android devices are also able to run Android applica-...
PrerequisitesThe main programming language for Android is Java. But beware,only a subset of the Java libraries are support...
ground and is therefore not tied directly to a visual representa-tion.   A message receiver handles messages broadcast by ...
latency and GPS position. It can also be used to view     memory consumption or kill processes. If this tool is     runnin...
If you are implementing your application against Android3.1+, you will be able to make homescreen widgets resizableand con...
SigningYour application is always be signed by the build process, eitherwith a debug or release signature. You can use a s...
Android 1.6 upwards also supports in-app purchase. This en-ables you to sell extra content, feature sets and such like fro...
Programming bada Appsbada is Samsung’s proprietary smartphone platform and is basedon open-source tools and software. bada...
tasking, which makes real background services possible. In addi-tion, bada 2.0 supports Near Field Communication as well a...
ImplementationAfter creating an application manifest you can start with appdevelopment using the bada SDK/IDE. The IDE has...
bada, but the lack of RTTI and exceptions can make it challeng-ing work.   The bada API itself is wrapped in a number of n...
Flash based applicationsFlash    based    applications       make     use     of    theOsp::Ui::Controls::Flash control of...
if(pReceivedMethod->		Equals(L”SendDataEvent”,true)) {		pFlash->SendDataEventToActionScript(		L”TestExtension”,dataList);	...
—— Content links for download external content are not sup-   ported and queried sites from a link (<a href>) will be   lo...
Another new tool that was introduced with bada 2.0 SDK is acode coverage and performance-monitoring tool, which enablescod...
ProgrammingBlackBerry AppsThe BlackBerry platform is developed by Canadian company Re-search In Motion (RIM)1 and was laun...
PrerequisitesRIM currently supports two platforms/ operating systems: Black-Berry OS and BlackBerry PlayBook OS. The futur...
For phones, future OS is called BlackBerry 10 and will bebased on PlayBook OS, replacing the current BlackBerry OS even-tu...
Coding Your ApplicationThe BlackBerry JDE is partly based on Java ME and some of itsJSR extensions: Integrated into the SD...
pulling the updates from the server. This reduces network traffic,battery usage and, for users on metered data plans or ro...
PortingPorting between BlackBerry devices is easy because the OS ismade by a single company that has been careful to minim...
SigningMany security-critical classes and features of the platform (suchas networking or file APIs) require an application...
Programming Flash AppsAdobe Flash is a multimedia platform used to add animation,video, and interactivity to web pages and...
PrerequisitesAdobe open sourced the Flash specification, permitting inde-pendent developers and companies to develop Flash...
Be sure to save your Flash files in a format that is compatiblewith your target device’s software.   Pay special attention...
ActionScript 2 and requires a lot more development know-howand experience to implement efficiently.You might also want to ...
TestingThe best approach for initial testing is determined by yourchosen architecture: If you have developed an Adobe Flas...
Packaging And DistributionWhen you design Flash content for use in a mobile website, pack-aging and distribution is straig...
Programming iOS AppsiOS, running on the iPhone, iPod touch and iPad, is a very in-teresting and very popular development p...
and over 1,500 new APIs for developers. One of the most inter-esting is iCloud, which provides for easy cloud storage of a...
The iOS SDK will work on any Intel-based Mac running Mac OSX 10.6 (Snow Leopard) or 10.7 (Lion, which is the recommendedOS...
Alternative Third-Party Development EnvironmentsSince Apple relaxed their App Store distribution guidelines, de-velopment ...
most sense for games, which can share almost all their codebetween different platforms. Java IDE makers JetBrains recently...
TestingAs performance in the iPhone Simulator can be superior to theperformance on a device, it is absolutely vital that t...
Google Toolbox for Mac10 runs test cases using a shell scriptduring the build phase, while GHUnit11 runs the tests on thed...
other aspect of the iPhone ecosystem. A list of common rejectionreasons can be found on www.apprejections.com. Recently, A...
Intermediate booksBooks suited for those who have had some exposure to the iOSSDK and are looking to deepen their knowledg...
CommunityOne of the most important aspects of iOS development is thecommunity. Many iOS developers are very forthcoming an...
ProgrammingJ2ME / Java ME AppsJ2ME (or Java ME as it is officially called) is the world’s mostwidespread mobile applicatio...
However, if your business model relies on direct applicationsales, or if your application needs to make use of state-of-th...
—— Depending on your setup you may need an obfuscator like   ProGuard8. If you build applications professionally you will ...
ImplementationThe Java ME platform is fairly straight-forward: it comprisesthe Connected Limited Device Configuration (CLD...
application execution, so it is possible for applications to runin the background. However, this usually requires the use ...
1.	 J2ME Polish16: This tool separates the design in CSS and      you can use HTML for the user interface. It is backward-...
tion’s size as small as possible. This results in cheaper downloadsfor your users (as less data traffic is needed) and gre...
Automated TestingThere are various unit testing frameworks available for Java ME,including J2MEUnit24, MoMEUnit25 and CLDC...
Lowest Common DenominatorYou can prevent many porting issues by limiting the functional-ity of your application to the low...
—— Client libraries that simplify development—— Build tool chains that convert code and resources to ap-   plication bundl...
uses one of those features, is largely dependent on the imple-mentation.    On one phone the user might be asked once to e...
the-Air (OTA). However, app stores are probably the most ef-ficient way to distribute your apps.: They manage the payment,...
Programming Qt AppsPronounced “cute” – not “que-tee” – Qt is an application frame-work that is used to create desktop appl...
communication between objects1; the output from one objectis a “signal” that has a receiving “slot” function in the same o...
PrerequisitesQt SDK3 installs everything you need to create, test, and debugapplications for Symbian phones and the Nokia ...
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Mobile Developer's Guide To The Galaxy No.10
Upcoming SlideShare
Loading in...5
×

Mobile Developer's Guide To The Galaxy No.10

4,732

Published on

The community-driven, non-commercial, free handbook about mobile technologies. Learn everything about the differences between the platforms, cross-platform approaches and key topics like how to implement NFC, security or haptics in mobile apps.
If you want the book as a hardcopy or want to get involved as a writer or sponsor, write to developers@enough.de

Published in: Technology
5 Comments
2 Likes
Statistics
Notes
No Downloads
Views
Total Views
4,732
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
70
Comments
5
Likes
2
Embeds 0
No embeds

No notes for slide

Mobile Developer's Guide To The Galaxy No.10

  1. 1. 10EDIT ION th TEN Xom D c E ED ple UPDATtely & ED S TI L EE F OR F R L
  2. 2. published by: Services and Tools for All Mobile Platforms Enough Software GmbH + Co. KG Sögestrasse 70 28195 Bremen Germany www.enough.dePlease send your feedback, questions or sponsorship requests to: developers@enough.de Follow us on Twitter: @enoughsoftware 10th Edition February 2012 This Developer Guide is licensed under the Creative Commons Some Rights Reserved License. Design and Artwork by Andrej Balaz (Enough Software) Character Artwork by Johanna Kromp (www.organisiertekunst.de)
  3. 3. Mobile Developer’s GuideTable of Contents1 Introduction4 An Overview Of Application Platforms4 Native Applications6 Java ME (J2ME)6 Flash7 BREW7 Websites And Web Apps8 Web Widgets10 SMS Text Messaging11 Programming Android Apps13 Prerequisites13 Implementation16 Testing17 Signing17 Distribution19 Programming bada Apps20 Getting Started21 Implementation25 Documentation & bada Resources25 Testing26 Distribution
  4. 4. 27 Programming BlackBerry Apps28 Prerequisites30 Coding Your Application30 Services31 Testing32 Porting33 Signing33 Distribution34 Programming Flash Apps35 Prerequisites36 Tips And Tricks38 Testing39 Packaging And Distribution40 Programming iOS Apps41 Prerequisites44 Implementation45 Testing46 Distribution47 Books49 Community50 Programming J2ME / Java ME Apps51 Prerequisites53 Implementation56 Testing57 Porting59 Signing60 Distribution
  5. 5. 62 Programming Qt Apps64 Prerequisites64 Creating Your Application66 Testing67 Packaging67 Signing68 Distribution71 Programming Symbian Apps72 Prerequisites73 Testing73 Signing74 Distribution75 Programming Windows Phone Apps76 UI Design77 Development80 Functions and Services80 Multitasking and Application Lifecycle81 Native Code82 Distribution83 Testing And Analytics84 Monetization85 Resources87 Programming Windows 8 Apps87 Prerequisites88 Developing Metro Style Apps93 Distribution94 Resources
  6. 6. 95 Programming Mobile Widgets96 Widget Characteristics100 Prerequisites100 Writing Your Code102 Testing104 Signing104 Distribution105 Programming With Cross-Platform Tools106 Limitations And Challenges Of Cross Platform Approaches111 Cross-Platform Strategies115 Cross-Platform Solutions119 Creating Mobile Websites119 Context Is King120 Usability Aspects122 Technical Limits of Web Technologies125 Fragmentation126 Website Adaptation130 Hybrid Apps131 Lessons Learned133 Developing Accessible Apps133 General Platform Accessibility134 Making Your App Accessible138 In Conclusion
  7. 7. 139 Implementing Rich Media139 Streaming vs. Local Storage141 Progressive Download141 Media Converters142 Implementing Location-Based Services142 How To Obtain Positioning Data144 How To Obtain Mapping Services145 Implementing Location Support On Different Platforms147 Tools For LBS Apps149 Implementing Near Field Communication (NFC)151 Support For NFC151 Creating NFC Apps
  8. 8. 153 Implementing Haptic Vibration157 Basic Vibration Control on Android158 Extending Basic Vibration Control159 Implementing Security Measures160 General Concepts161 The Threats To Your Applications162 Hiding the Map of Your Code163 Hiding Control-Flow164 Active Protection That Stays With The Application164 White-Box Cryptography165 Protection Tools166 Resources166 The Bottom Line167 Testing Your Application167 Testability: The Biggest Single Win168 Headless Client168 Separate The Generic From Specific169 Test-Driven Development169 Physical Devices170 Remote Control171 GUI Test Automation171 Beware Of Specifics171 Crowd-Sourcing172 Web-Based Content And Applications  8
  9. 9. 173 Monetization174 Pay Per Download177 In-App Payment178 Mobile Advertising179 Revenue Sharing179 Indirect Sales180 Marketing And Promotion181 Strategy182 What Can You Earn?183 Appstores184 Basic Strategies To Get High185 Multi-Store vs Single Store187 Now What – Which Environment Should I Use?187 The Business Perspective: Market Reach191 The Developer’s Perspective: Technology195 Epilogue196 About the Authors
  10. 10. IntroductionWelcome to the 10th anniversary edition of our Mobile Develop-ers Guide To The Galaxy! We introduced the first version of thisoverview of mobile technology exactly 3 years ago, at MobileWorld Congress 2009. And we are flattered to see that it hasgrown from a thin brochure into a small book, and become oneof the best-known publications about app development. All thiswould not have been possible without the community’s support:Our thanks go out to all the writers who are sharing their know-how on the following pages, to the printing sponsors for theirfinancial support and to all the individuals who are helping todistribute the book at events and among universities, schoolsand other organizations worldwide. We are also glad to inform you that our friends from WIPhave started to put out a companion guide to this book: Gettheir “Mobile Developer’s Guide To The Parallel Universe” onwww.wipconnector.com or on their WipJams and learn everythingabout app marketing. As always the ever-changing kaleidoscope of the mobile in-dustry does just that — it keeps changing. Since our last edi-tion: Windows 8 was revealed, Adobe discontinued Flash for Introduction 1
  11. 11. mobile browsers, Tizen released a preview SDK, HP changed itsmind and announced webOS would continue as an Open Sourceproject, Sony separates from Ericsson, Nokia released its firstWindows Phone products and acquired Smarterphone, BlackBerryseemingly jumps off the Java bandwagon with BlackBerry 10,Android expanded its reach to TVs and other appliances, Applemade the world speak to its phone and much more. As usualthese changes are reflected in this guide. We have also addedtwo completely new chapters: how to implement haptics intoyour app and how you can protect your code against securityattacks right from the start. We hope you enjoy the book and we are looking forward to see-ing the project continue to grow. Please get involved and let usknow what content might be missing, at developers@enough.de.Robert + Marco / Enough SoftwareBremen, February 2012 2
  12. 12. An Overview Of ApplicationPlatformsThere is a wide selection of platforms with which you can realizeyour mobile vision. This section describes the most common en-vironments and outlines their differences. More detailed descrip-tions follow in the platform-specific chapters.Native ApplicationsThere are many mobile platforms used in the market – some areopen source, some are not. The most important native platformsare (alphabetically) Android, bada, BlackBerry, BlackBerry Play-Book OS (QNX), iOS, Symbian, Windows 8 and Windows Phone. All these platforms enable you to create native applicationswithout establishing a business relationship with the respectivevendor. The main benefits of programming apps natively include bet-ter integration with the platform’s features and often better per-formance. Typical drawbacks are the effort and complexity ofsupporting several native platforms (or limiting your app to oneplatform). Most mass market featurephones are, however, equipped withembedded operating systems that do not offer the opportunityto create native applications. Examples include but are not lim-ited to Nokia Series 40, Samsung SGH and LG featurephones. The following table provides an overview of the main mobileplatforms: An Overview Of Application Platforms 4
  13. 13. Platform Language(s) RemarksAndroid Open Source OS (based on Linux) Java, C, C++ developer.android.com Samsung’s mobile platform runningbada C, C++ on Linux or RealTime OS developer.bada.com Java ME compatible, extensionsBlackBerry Java, Web Apps enable tighter integration blackberry.com/developersBlackBerry Tab- ActionScript, The forthcoming BlackBerry 10 OSlet/PlayBook C++, HTML, CSS, will be based on QNX as wellOS (QNX) JavaScript blackberry.com/developers The mobile OS that introducediOS Objective-C, C mobile apps to ordinary people. developer.apple.com/iphone C, C++, Java, Currently the longest running of allSymbian Qt, Web Apps, smartphone OSs others www.forum.nokia.com/symbian Supports native HTML5 HTML, CSS, programming, (based on Linux),webOS JavaScript, C future should be Open Source developer.palm.com C#/VB.NET, C++, Microsoft’s first real tablet OSWindows 8 JavaScript msdn.microsoft.com/en-us/windows/appsWindows Silverlight, XNA frameworks C#, VB.NETPhone create.msdn.com An Overview Of Application Platforms 5
  14. 14. Java ME (J2ME)Around 70% of all featurephones worldwide support the mobileJava standard (Java ME formerly known as J2ME), making it byfar the most widely distributed application environment. In con-trast to many other environments, Java ME is a standard ratherthan a product, which can be implemented by anyone (who paysOracle the corresponding license fees that is). Standardization isthe strength of Java ME but at the same time it’s the source ofmany fragmentation problems. On many feature phones, Java ME is the only way to real-ize client side applications. With the increasing penetration ofsmartphones, Java ME has lost importance, at least in the US andEurope. However, as TechCrunch puts it: With 27% smartphonemarket share, it´s still a feature phone world out there1. That iswhy, particularly in emerging economies, Java ME remains themain option to target the mass market. It has been also hailedas the fastest growing platform for mobile devices, driven bythe demand for feature rich yet inexpensive phones in emergingeconomies2.FlashHistorically, Flash Lite was the mobile edition of Flash, but basedon an older version of Adobe’s web Flash product with Action-Script 2.0 support. After phasing out Flash Lite for mobile andmoving to the full version of Flash, Adobe has now announcedit will discontinue Flash for mobile browsers altogether. InsteadFlash based Adobe AIR apps along with HTML5 apps are the Ado-be’s focus for this market.1  techcrunch.com/2011/11/28/its-still-a-feature-phone-world-global- smartphone-penetration-at-27/2  www.theregister.co.uk/2012/01/03/apple_losing_the_race_for_emerging_ economies_cash An Overview Of Application Platforms 6
  15. 15. Flash is favored by many designers, since they know the toolsalready and it can be used to create engaging, powerful userinterfaces (UIs). It’s relatively easy to code thanks to the Ac-tionScript language, which is very similar to JavaScript. The drawbacks of Flash on mobile devices used to be poorperformance, suboptimal integration into host devices and smallmarket share in comparison to Java ME. Nevertheless there aremillions of feature phones supporting Flash Lite today and manysmartphones and tablets can support some Flash content includ-ing Symbian, iOS (through Adobe AIR), Android and BlackBerrydevices.BREWThe Binary Runtime Environment for Wireless (BREW) is a featurephone programming environment promoted by Qualcomm3. BREW services are offered by more than 60 operators in 28countries, but it’s most popular within the US with CDMA deviceslaunched by Verizon, US Cellular and Metro PCS, among others.While previous versions supported C development only, theBrew Mobile Platform (Brew MP), supports applications writtenin Java, Flash, TrigML or native C code4.Websites And Web AppsThe browsing of web pages is supported by most phones, soin principle this should be the environment of choice to getthe widest possible reach (after SMS text messaging). However,the sheer number of browsers and their varying feature sets can3  www.brewmp.com4  developer.brewmp.com An Overview Of Application Platforms 7
  16. 16. make this approach challenging. Some browsers are very power-ful and support CSS as well as JavaScript; others are less sophis-ticated and support XHTML only. Thankfully the old WAP standardwith its WML pages doesn’t play any significant role nowadays. The main drawback of web pages is that they are availablewhen the device is online only and their access to device fea-tures is extremely limited. Even with these challenges, the mo-bile web as a platform offers benefits in ease of development andcontrol over deployment. With the introduction of HTML5 and new mobile browsers thatsupport its features, this situation is improving: Offline brows-ing and new device APIs, such as for location information, arebecoming available to mobile websites.Web WidgetsAs HTML5 support matures, it will probably become the mostpopular way to create web apps for mobile phones. In the mean-while several platforms offer web widgets (essentially a smallwebsite packaged for installation on a device). Web widgets gen-erally offer the advantage of APIs to access platform featuresand can be distributed through app stores. Proxy based web widgets for, feature phone platforms, arelikely to remain popular even after HTML5 web apps largely re-place web widgets on smartphone.Some notable web widget environment are listed on the follow-ing page. An Overview Of Application Platforms 8
  17. 17. Environment Language(s) Remarks Standard web technology basedSymbian widgets, with a proprietary packag-Web Runtime XML, HTML, CSS, ing standard. JavaScript APIs offer(WRT) JavaScript high degree of access to platformWidgets features. www.forum.nokia.com/Develop/Web A joint initiative by Vodafone, China Mobile and other compa- XML, HTML,WAC nies are pushing the W3C widget JavaScript, CSS standard wacapps.net/developers XML, HTML, CSS,Samsung innovator.samsungmobile.com JavaScript Web apps for the proxy based Series 40 Browser enabling UISeries 40 XML, HTML, CSS, manipulation on a device throughweb apps JavaScript JavaScript. W3C packaging stan- dard used. www.forum.nokia.com/webapps HTML, CSS, Cross platform web app platformPhoneGap JavaScript www.phonegap.comSony Ericsson HTML, CSS, Based on PhoneGapWebSDK JavaScript developer.sonyericsson.comBlackBerry HTML, CSS, blackberry.com/developersWebworks JavaScript An Overview Of Application Platforms 9
  18. 18. SMS Text MessagingAlmost everybody who has a mobile phone is also texting. Tex-ting limits interactions to less than 160 characters; and it can bequite costly to send out text messages in bulk. On the positiveside, SMS enjoys a global audience of all ages. It also plays animportant role in emerging markets where, for example, its usefor payments is common. Note that some tablets such as the iPad or the Samsung Gal-axy Tab use WiFi instead of a mobile phone networks and thesedevice cannot send SMS messages directly. However, some opera-tors offer APIs for messaging services that work for WiFi-onlydevices, such as the network APIs of Deutsche Telekom. 55  www.developergarden.com/apis/ An Overview Of Application Platforms 10
  19. 19. Programming Android AppsThe Android platform is developed by the Open Handset Allianceled by Google and has been publicly available since November2007. Android is an operating system, collection of preinstalled ap-plications and an application framework (Dalvik) supported bya comprehensive set of tools. Its use by many hardware manu-facturers has made it the fastest growing smartphone operatingsystem. Although the acquisition of Motorola’s handset businessby Google in late 2011 could affect the platform’s use by othermanufacturers, it is not expected to. According to Gartner, morethan 50% of all smartphones sold in Q3 2011 worldwide werebased on Android1, more than 400,000 apps are available in theAndroid Market2. Android is also used in tablets, media players,1  www.gartner.com/resId=18473152  www.distimo.com/blog/2012_01_google-android-market-tops-400000- applications/ Programming Android Apps 11
  20. 20. set-top boxes, desktop phones and car entertainment systems.Some non-Android devices are also able to run Android applica-tions, such as RIM’s PlayBook with its virtual machine calledApp player3. The platform continues to evolve rapidly, with the regular ad-dition of new features every 6 months or so. The current AndroidOS version 4.0 (“Ice Cream Sandwich”) was designed to serve asplatform for both phones and tablets. It brings interesting newfeatures such as a Face Detection API, WiFi-Direct, Hardware-ac-celerated 2D-drawing and an easier to use NFC-API called Beam4.The first phone based on Ice Cream Sandwich was the SamsungGalaxy Nexus introduced in October 2011, first tablets with An-droid 4.0 followed in December. One of the most discussed issues when developing for Androidis fragmentation: The multitude of different devices by differ-ent manufacturers and the fast progress of the platform itselfleads to uncertainty over whether your Android application willrun everywhere. In addition, only a very small number of phoneand tablet models support the latest OS version. However, todayyou will reach 98.3% of the installation base if you decide todevelop against Android 2.1 or above5. To reduce fragmenta-tion issues caused by large differences in screen size, Android3.2 (“Honeycomb”) introduced a new resource descriptor called“smallestWidth” which can be used to target phones and tabletswith different layout depending on their dimensions6. With Android 4.0 there is now also a design guide for Androidapps available at developer.android.com/design.3  www.theregister.co.uk/2011/03/25/rim_playbook_android/4  developer.android.com/sdk/android-4.0-highlights.html5  developer.android.com/resources/dashboard/platform-versions.html6  developer.android.com/guide/practices/screens_support.html#NewQualifiers Programming Android Apps 12
  21. 21. PrerequisitesThe main programming language for Android is Java. But beware,only a subset of the Java libraries are supported and there aremany platform specific APIs. You can find answers to your “Whatand Why” questions in the Dev Guide7and to your “How” ques-tions in the reference documentation8. To get started, you need the Android SDK9, which is availablefor Windows, Mac OS X and Linux. It contains the tools neededto build, test, debug and analyze applications. You will probablyalso want a good Java IDE. Eclipse or IntelliJ seem good choices.These IDEs offer good support for development, deployment and– importantly – library projects that enable the sharing of codeand resources between projects. Command line tools and Ant build scripts are also provided,so you can create almost any development and build process. The Android Developer Tools for Eclipse bring nice featureslike Lint10, which helps in optimizing applications by pointingout common bugs. The optimizations are thankfully easy toimplement.ImplementationAn Android application is a mix of activities, services, messagereceivers and data providers declared in the application mani-fest. An activity is a piece of functionality with an attached userinterface. A service is used for tasks that should run in the back-7  developer.android.com/guide8  developer.android.com/reference9  developer.android.com/sdk10  tools.android.com/recent/lint Programming Android Apps 13
  22. 22. ground and is therefore not tied directly to a visual representa-tion. A message receiver handles messages broadcast by the systemor other applications. A data provider is an interface to the con-tent of an application that abstracts from the underlying stor-age mechanisms. An application may consist of several of thesecomponents, for instance an activity for the UI and a service forlong running tasks. Communication between the components is done by intents.An intent bundles data, such as the user’s location or an URL,with an action. These intents trigger behaviors in the platform.For instance, the intent of showing a web page will open thebrowser activity. The powerful thing about this building-blockphilosophy is that functionality can be replaced by another ap-plication, as the Android system always uses the preferred ap-plication for a specific intent. For example, the intent of sharing a web page triggered by anews reader app can open an email client or a text messagingapp depending on the user’s preference and the applications in-stalled: Any application that declares the sharing intent as theirinterface can be used. To aid development, you have many tools at your disposal inthe SDK, the most important ones are:—— android: To create a project or manage virtual devices and versions of the SDK.—— adb: To query devices, connect and interact with them (and virtual devices) by moving files, installing apps and such like.—— emulator: To emulate the defined features of a virtual device. It takes a while to start, so do it once and not for every build.—— ddms: To look inside your device or emulator, watch log messages and control emulator features such as network Programming Android Apps 14
  23. 23. latency and GPS position. It can also be used to view memory consumption or kill processes. If this tool is running, you can also connect the Eclipse debugger to a process running in the emulator. Beyond that ddms is the only way (without root-access) to create screenshots in Android versions below 4.0. These four tools and others – such as tools to analyze methodtrace logs, inspect layouts and test apps with random events orbackup functionality – can be found in the tools directory ofthe SDK. The user interface of an application is separated from thecode in Android-specific xml layout files. Different layouts canbe created for different screen sizes, country locales and devicefeatures without touching the Java code. To this end, localizedstrings and images are organized in separate resource folders.IDE plug-ins are available to help manage all these files. If you are facing issues, such as exceptions being thrown,be sure to check the ddms log. It enables you to check ifyou have omitted to add necessary permissions, such asandroid.permission.INTERNET., using the uses-permissionflags11. If you are going to use Honeycomb related layout features– such as Fragments12 – for large screens, be sure to add the An-droid Compatibility package from Google. It’s available throughthe SDK & AVD Manager and helps to develop for Android 3.0+without causing problems with deployment to Android 1.613through to Android 2.3. Be sure to use the v4 packages in yourapplication to provide maximum backwards support.11  developer.android.com/reference/android/Manifest.permission.html12  developer.android.com/guide/topics/fundamentals/fragments.html13  android-developers.blogspot.com/2011/03/fragments-for-all.html Programming Android Apps 15
  24. 24. If you are implementing your application against Android3.1+, you will be able to make homescreen widgets resizableand connect via USB to other devices, such as digital cameras,gamepads and many others.TestingThe first step to test an app is to run it on the emulator or de-vice. You can the debug it, if necessary, through the ddms tool.All versions of the Android OS are built to run on devices withoutmodification, however some hardware manufacturers might havechanged pieces of the platform14. Therefore, testing on a physi-cal device is essential.Automated TestingTo automate testing, the Android SDK comes with some capableand useful testing instrumentation15 tools. Tests can be writtenusing the standard JUnit format using the Android mock objectsthat are contained in the SDK. The Instrumentation classes can monitor the UI and send sys-tem events such as key presses. You can test then for the statusof your application after these events have occurred. The auto-mated tests can be run on virtual and physical devices. Open-source testing frameworks, such as Robotium16 can complementyour other automated tests. Robotium can even be used to testbinary apk files, if the source is not available. A maven plugin17and a helper for the continuous integration of a Hudson servermay also assist your testing18.14  For an overview see e.g. www.androidfragmentation.com15  developer.android.com/guide/topics/testing/testing_android.html16  code.google.com/p/robotium17  code.google.com/p/maven-android-plugin/18  wiki.hudson-ci.org/display/HUDSON/Android+Emulator+Plugin Programming Android Apps 16
  25. 25. SigningYour application is always be signed by the build process, eitherwith a debug or release signature. You can use a self-signingmechanism, which avoids signing fees (and security). The same signature must be used for updates to your ap-plication. Remember that you can use the same key for all yourapplications or create a new one for every app.DistributionAfter you have created the next killer application and tested it,you should place it in the Android Market. This is a good placeto reach both customers and developers of the Android platform,to browse for exciting new apps and to sell your own apps. Itis also used by other app portals as a source for app metada-ta. To upload your application to the Android Market, start atmarket.android.com/publish. You are required to register with the service using yourGoogle Checkout Account and pay a $25 registration fee. Onceyour registration is approved, you can upload your application,add screenshots and descriptions and publish it. Make sure that you have defined a versionName, versionCode,an icon and a label in your AndroidManifest.xml. Further-more, the declared features in the manifest (uses-feature nodes)are used to filter apps for different devices. As there are lots ofcompeting applications in Android Market, you might want touse alternative application stores. They provide different pay-ment methods and may target specific consumer groups19.19  www.wipconnector.com/index.php/appstores/tag/android Programming Android Apps 17
  26. 26. Android 1.6 upwards also supports in-app purchase. This en-ables you to sell extra content, feature sets and such like fromwithin your app, using the existing infrastructure of the AndroidMarket20. There are other interesting alternatives to the Android Marketwhich can help you target a certain audience. One of those mar-kets is the Amazon Appstore, which comes preinstalled on theKindle Fire. For more information about appstores, please referto the dedicated chapter in this guide.20  developer.android.com/guide/market/billing/index.html 18
  27. 27. Programming bada Appsbada is Samsung’s proprietary smartphone platform and is basedon open-source tools and software. bada was introduced in late2009 and the first version of the SDK was released to the publicin June 2010. Samsung’s main reason for introducing bada wasto accommodate the anticipated need for smartphone featuresat the low-end of the market. Because bada can run on top ofa Linux kernel for high-end devices or a real-time OS kernels forlow-end devices, all market segments can be served. Samsung puts a high priority on developer support and train-ing. There is a huge documentation and guide library availablefrom the developer site developer.bada.com. This site offers aforum, premium support and direct access to Samsung bada ex-perts as well. Samsung’s application store gives developers a route to mar-ket and includes features such as sales and download statistics,advertising and a direct feedback channel for customers. Thestore is accessible to customers through a website1, a client ap-plication on bada smartphones and a PC client called Samsung’sKies. Applications can be offered as paid apps or free. In thecase of a purchased app, you will receive 70% of sales, which isthe same offer as most other popular mobile application stores.It is possible to generate revenue by placing adverts in yourapps too. Currently there are ten bada-based devices available with theWave 3 being the current flagship device and Wave 578, the firstdevice with NFC hardware running bada 2.0. bada 2.0 – released in September 2011 – introduced multi-1  www.samsungapps.com Programming bada Apps 19
  28. 28. tasking, which makes real background services possible. In addi-tion, bada 2.0 supports Near Field Communication as well as thepossibility for easy ad-hoc WiFi-P2P network setup from withinthe SDK. Other interesting features include enhancements to theUX with speech-to-text (STT) and text-to-speech (TTS), as wellas support for 3D sound with OpenAL. Furthermore, the supportfor web-based applications is extended, with more JavaScriptframeworks, HTML5 and a lot of APIs from the WAC 2.0 standardwithin the Webcontrol. Another interesting new feature is theMIME-type registration for applications, so that you can registerapplications to the system for handling specific file or mediatypes, such as MP3.Getting StartedYou get start with developing for bada by registering atdeveloper.bada.com, there is no charge for this. Next, downloadthe bada SDK, which is available for Microsoft Windows basedcomputers only. The SDK includes the bada IDE (based on EclipseCDT), an emulator and a GNU toolchain. Before starting to program you should be familiar with theapplication manifest, which is a unique application profile. Thisprofile is needed to enable debugging and testing of applica-tions on devices and distribution of apps through the store. Amanifest can be generated and managed on developer.bada.comunder the menu item “My Application”. You can create feature-rich bada apps with the C++ frame-work for C++/ Flash-based applications or the Web frameworkfor developing applications based on standard web technologies,such as HTML, CSS and JavaScript. The bada project templates,included in the IDE, provide a good starting point for bada ap-plication development for all of these technologies. Programming bada Apps 20
  29. 29. ImplementationAfter creating an application manifest you can start with appdevelopment using the bada SDK/IDE. The IDE has a plentifullibrary of example code and this code can be copied with oneclick into your own workspace. These examples are a great wayto get familiar with the features of bada and its programmingparadigm.C++ Based ApplicationsNative bada apps are developed in C++. Some restrictions applyhowever, for example, the language does not use exceptions.Instead, it returns values and a combination of macros is usedfor error handling and RTTI is turned off, so that dynamic_castdoes not work on bada. When creating bada apps, you need to understand memorymanagement basics, because the language often leaves this upto you. For example, the app will have to delete any pointer re-turned by a method ending in ‘N’. You should also make sure thateach new variable has a delete method:MyType* var = new MyType(); // call deleteMyType* array 0 new MyType[10]; // call delete[]MyType type, stackarray[];// variable on stack will be destroyed by//scope, no delete The API uses some parts of STL, so while Samsung says thatSTL can be used in code, be aware that the current STL imple-mentation shipping with bada is missing some components. Thiscan be addressed by using STLPort for full STL support. Similarlyyou can port modern C++ Libraries, such as Boost, to work on Programming bada Apps 21
  30. 30. bada, but the lack of RTTI and exceptions can make it challeng-ing work. The bada API itself is wrapped in a number of namespaces.The API offers UI Control and Container classes, but there areno UI Layout management classes, so the UI elements must bepositioned by hand or within the code. An UI layout for thelandscape and/or the portrait mode is also your responsibility.The API provides most standard classes for XML, SQL or Networkand a pretty complete framework. You should make use of thecallbacks for important phone events in the application class,such as low battery level or incoming calls. When writing games for bada, the SDK supports OpenGL ES1.1 and 2.0. The SDK wraps parts of OpenGL for use in its ownclasses, making it easy to port existing OpenGL code to bada. Programming bada Apps 22
  31. 31. Flash based applicationsFlash based applications make use of theOsp::Ui::Controls::Flash control of the C++ framework:so a Flash based app is simply a Flash movie played within aC++ bada app. This means you are able to take advantage ofthe entire C++ API feature set, such as geolocations and accel-erometer. bada 2.0 is able to handle Adobe Flash Lite Version 4and ActionScript 3.0. To create an interface with the Flash app,use the fscommand2 and SendDataEventToActionScript()API calls. Following examples from the bada documentation willshow this roundtrip:fscommand2(“Set”,”SendDataEvent”, “/”);// Implement this callback method from the// Osp::Ui::IFlashEventListener Interface to// respond to the ActionScript// “Set” fscommand2 that we defined for the// PushButton Flash object.void FlashForm::OnFlashDataReceived (constOsp::Ui::Control &source,const Osp::Base::Collection::IList &mList){// code to extract the message and set up the data to send back goes here …// If this is the event we were expecting, send// a response Programming bada Apps 23
  32. 32. if(pReceivedMethod-> Equals(L”SendDataEvent”,true)) { pFlash->SendDataEventToActionScript( L”TestExtension”,dataList); }}More information on using Flash as application platform canbe found in the bada online help system under the menu entry“bada Flash App Programming”.Web based applicationsThe bada web framework uses HTML, JavaScript and CSS. Thesestandards are enriched by additional APIs (such as those definedby WAC) and other concepts. The web framework extends theobject-oriented programming concepts of JavaScript with fol-lowing paradigm:—— Class: Adopts object-oriented class concept with its defini- tion, members and types—— Inheritance: Adds the inheritance feature of object-orient- ed programming by using the extend key to a drive a new class.—— Mixins: Mixins provides a way to extend the functionality of existing classes without using inheritance.These will be explained in more detail in the bada frameworkdocumentation under “Basics of bada Web Programming”In addition you should be aware of following system limitations:—— Selected fonts from the Settings menu are not supported with web applications—— Only the bada 2.0 theme is supported in web applications Programming bada Apps 24
  33. 33. —— Content links for download external content are not sup- ported and queried sites from a link (<a href>) will be loaded into the same document page. For basic information on mobile web programming, please seethe respective chapter in this guide.Documentation & bada ResourcesThe central resource for bada developers is developer.bada.com.The biggest independent bada website and forum is currentlyBadaDev.com, which has a good library of great tutorials aboutcoding for bada. There is an IRC channel #bada at irc.freenode.net,and of course there are groups for bada developers on most so-cial networks.TestingThe bada API offers its own logging class and an AppLog meth-od; you should make extensive use of logging in debug builds. The AppLog will show up in the IDE. The IDE provides fortesting and debugging in the simulator or on a device. As men-tioned earlier in this guide, we strongly recommend testing ondevices. Without device testing you cannot be sure how the appwill perform and, in rare cases, code that worked perfectly on thesimulator will not do so on the handset. Samsung provides the bada Remote Test Lab (RTL), which isavailable for all registered developers, and can be installed asan Eclipse-plugin. Tools and frameworks for unit testing are available within theIDE/SDK. For details about these tools, check out the “bada Tu-torial Development Environment.pdf” included in the documentsfolder in the SDK base directory. Programming bada Apps 25
  34. 34. Another new tool that was introduced with bada 2.0 SDK is acode coverage and performance-monitoring tool, which enablescode optimizations.DistributionThere is only one option for distributing bada apps, Samsung‘sown appstore. As with Apple’s AppStore, there are quite strictacceptance rules for apps submitted. You can find out more inthe “Samsung Apps Publisher Guide,“ which can be downloadableafter registering at the Samsung Apps Seller Office. Once your app has made it to the store, you will get 70% ofthe revenue. For advertising Samsung own advertising service –AdHub – but also allows the inclusion of third party ad networkcontents. Programming bada Apps 26
  35. 35. ProgrammingBlackBerry AppsThe BlackBerry platform is developed by Canadian company Re-search In Motion (RIM)1 and was launched in 1999. BlackBerrydevices became extremely popular because they were equippedwith a full keyboard for comfortable text input (which spawneda condition named BlackBerry Thumb2), offered long battery lifeand included Blackberry Messenger, their mobile social networkoffering. Add PDA applications such as address book, secureemail, calendar, tasks and memopad to these features and youwill understand why the platform is very popular among businessand mainstream users alike. The market share of BlackBerry phones has declined some-what in the US in 20113, but it is still an important smartphoneplatform. While the general consensus seems to be that Black-Berry tablet – the PlayBook with its new QNX Neutrino-based OS– was been launched too early, the hardware and OS are highlypraised. In this edition we concentrate on Java development for theBlackBerry smartphones.1  www.rim.com2  en.wikipedia.org/wiki/Blackberry_thumb3  gs.statcounter.com 27
  36. 36. PrerequisitesRIM currently supports two platforms/ operating systems: Black-Berry OS and BlackBerry PlayBook OS. The future platform forBlackBerry devices is called BlackBerry 10 and has not beenlaunched yet. BlackBerry OS is the operating system found on all currentBlackBerry smartphones. Its latest iteration released in January2012 (BlackBerry OS 7.1) offers some notable improvements overits predecessor (BlackBerry OS 7): tethering, WiFi calling sup-port, NFC Tag support and FM radio. The most relevant API additions in OS 7.1 are:—— NFC Peer-to-Peer API, which offers the ability to initiate data transfers between two devices via NFC, then complete the transfer via Bluetooth—— FM Radio API—— Profiles API, which allows read/write access to the user’s current profile For BlackBerry OS, two development approaches are availabledepending on the type and nature of your planned project: Formid-sized to large applications native Java development is thebest choice; while small apps could be developed with the Black-Berry WebWorks SDK. RIM’s next generation operating system is based on the QNXNeutrino Realtime OS (RTOS). Currently RIM calls it PlayBookOS, as it is only supported on their PlayBook. Applications forPlayBook can be written using SDKs for Adobe AIR, WebWorksand Native C/C++. An Android compatibility layer, currently inbeta, is also available. There are currently no plans to supportthe existing BlackBerry Java API and SDK on PlayBook OS, whichis a major point of concern for many existing BlackBerry Javadevelopers. However, the Android compatibility layer somewhatcompensates for this. 28
  37. 37. For phones, future OS is called BlackBerry 10 and will bebased on PlayBook OS, replacing the current BlackBerry OS even-tually. The first regular BlackBerry smartphones running a ver-sion of this new operating system are scheduled to arrive in late2012. Although it will be phased out in the future, currently theBlackBerry Java API is the most commonly used method to de-velop BlackBerry apps. As such, this chapter focuses on Java de-velopment, for more information on WebWorks (web) and Flashprogramming please see the respective chapters in this guide.Java SDKAs for all Java-driven applications and development, you needthe Java SDK4 (not the Java Runtime Edition).IDEFor native Java development, you first need to decide which IDEto use. The modern option is to use Eclipse and the BlackBerryplugin5, for previous BlackBerry OS versions you can also use theBlackBerry Java Development Environments (JDEs)6. These JDEs are complete environments enabling you to write,compile, package and sign your applications. Device simulatorsare included as well.Desktop ManagerThe BlackBerry Desktop Manager7 should be downloaded and in-stalled. It enables you to deploy your app package on a devicefor testing. For faster deployment, you mightalso use a tool called javaloader that comeswith the JDE.4  www.oracle.com/technetwork/java5  us.blackberry.com/developers/javaappdev/javaplugin.jsp6  us.blackberry.com/developers/javaappdev/javadevenv.jsp7  us.blackberry.com/apps-software/desktop/ Programming BlackBerry Apps
  38. 38. Coding Your ApplicationThe BlackBerry JDE is partly based on Java ME and some of itsJSR extensions: Integrated into the SDK is the MIDP 2.0 standardwith popular JSR extensions that provide APIs for UI, audio, vid-eo, and location services among others8. This means that Black-Berry apps can be created using Java ME technologies alone. Another option is to use BlackBerry’s proprietary extensionsand UI framework that enable you to make full use of the plat-form. Native UI components can be styled to an extent, but theyinherit their look from the current theme, however overriding theField.applyTheme() method will prevent this. From OpenGL-ES to homescreen interaction and cryptography,the BlackBerry APIs provide you with everything you need to cre-ate compelling apps. In addition to the official BlackBerry tools,there are third party extensions that enable you to enhance yourapps, for example J2ME Polish9 or Glaze10 which enable you todesign and animate your UI using CSS.ServicesBlackBerry offers many services that can be useful in developingyour applications including advertising, mapping, payment andpush services11. The push service is useful mainly in mail, messaging or newsapplications. Its main benefit is that the device waits for theserver to push updates to it, instead of the device continuouslypolling the server to find out if updates are available and then8  www.blackberry.com/developers/docs/6.0.0api/index.html9  www.j2mepolish.org10  www.glaze-ui.org11  us.blackberry.com/developers/platform Programming BlackBerry Apps 30
  39. 39. pulling the updates from the server. This reduces network traffic,battery usage and, for users on metered data plans or roaming,lowers costs. The push service12 works as follows: Your server sends a datapackage of up to 8KB to the BlackBerry push infrastructure.The infrastructure then broadcasts the message to all or a groupof clients (for content such as a news report) or to one specificclient (for content such as a chat message). The device clientthen receives the message through BlackBerry’s Push API andmay confirm message receipt back to the infrastructure. Yourserver can then check if the message was delivered. BlackBerryoffers the push mechanism as a limited free service, with a pre-mium paid extension that enables you to send more push mes-sages.TestingBlackBerry provides simulators for various handsets in the JDEand plug-ins or as separate downloads. These simulators enableyou to run an app on a PC in the same way it would be run ona device. To assist with testing, the simulators include featuressuch as simulating incoming calls and setting the signal strengthenabling you to check how your application reacts if a device isoutside network coverage. Applications running on the emula-tors are fully debuggable with breakpoints. As a great plus, BlackBerry devices provide the capability toperform on-device debugging with all the features that you en-joy from the simulators.12  us.blackberry.com/developers/platform/pushapi.jsp Programming BlackBerry Apps 31
  40. 40. PortingPorting between BlackBerry devices is easy because the OS ismade by a single company that has been careful to minimizefragmentation issues. However, this does not entirely eliminatechallenges:—— Some classes and functionalities are only available on specific OS versions. For example the FilePicker that is used to choose a file is only available from OS 5.0 onwards.—— You need to handle different screen resolutions and orien- tation modes (landscape and portrait).—— You need to handle touch and non-touch devices. In addi- tion, the Storm devices use a touchscreen that is physically clickable, so there is a distinction between a touch and a click on these devices. BlackBerry’s more recent touch devices don’t use this technology anymore. Porting to other Java platforms such as J2ME and Androidis complicated as it’s not possible to port the BlackBerry UI.Code written for server communication and storage etc mightbe reused on J2ME and Android if you avoid native BlackBerryAPI calls. In general, cross-platform portability strongly dependson how frequently your app uses native BlackBerry components.For example it is not possible to reuse BlackBerry push servicesclasses on other platforms. Programming BlackBerry Apps 32
  41. 41. SigningMany security-critical classes and features of the platform (suchas networking or file APIs) require an application to be signedsuch that the publisher can be identified. To achieve this, youneed to obtain a signing key directly from BlackBerry13. Thesigning itself is undertaken using the rapc tool which also pack-ages the application.DistributionBlackBerry’s own distribution channel is called App World14where you can publish your apps. For paid applications, you’llget a 70% revenue share. In addition, GetJar15 is a well-knownindependent website that also publishes BlackBerry apps.13  www.blackberry.com/SignedKeys/14  appworld.blackberry.com15  www.getjar.com 33
  42. 42. Programming Flash AppsAdobe Flash is a multimedia platform used to add animation,video, and interactivity to web pages and mobile apps. It com-bines vector and raster graphics with ActionScript for interactiv-ity. Flash development experienced a setback in November 2011,when Adobe announced that Flash would no longer developa version for mobile web browsers. Instead Flash developersshould concentrate on Adobe AIR1 development that can beused to develop native apps based on Flash. At the same timeAdobe jumped on the HTML5 bandwagon by demonstrating itsHTML5 authoring suite edge and by purchasing PhoneGap. Butall is not lost, an active developer community and third-partyecosystem around Flash ensures its continued existence. Also,RIM announced2 that they will continue their support of theFlash browser plugin for PlayBook itself. Many feature phoneshave support for the older and discontinued Flash Lite3 (typicallysupport for Flash Lite 3, 6 or 8 depending on when the devicewas manufactured). Development of mobile Flash applications can be undertakenusing Adobe products and alternative Flash-compatible SDKsfrom a number of vendors.1  www.adobe.com/products/air2  www.theverge.com/2011/11/9/2550815/rim-to-continue-developing-flash- browser-plug-in-for-playbook3  en.wikipedia.org/wiki/Adobe_Flash_Lite Programming Flash Apps 34
  43. 43. PrerequisitesAdobe open sourced the Flash specification, permitting inde-pendent developers and companies to develop Flash-compatibleSDKs, engines and players. Authoring can be undertaken usingthe Adobe Flash Professional or Adobe Creative Suite (CS) soft-ware. CS 5 supports ActionScript 3 and Flash 10.X offering the full3D and 2D feature set on some smartphones and tablets. If youwant to use features such as 3D and ActionScript 3 compatibility,using the CS5 package and tools is the way to go. However, one potential drawback of Flash is poor perfor-mance: Large binary files may run slowly on less powerful de-vices, resulting in a poor user experience. Adobe CS 3, 4 and5 can be used to author Flash content that runs on alternativeFlash-compatible SDKs, engines and players, giving developersmore options to optimize an application’s performance. These alternative Flash-compatible SDKs generally supportActionScript 2 and Flash 8 with a full 2D feature set. Note thatvideo and audio playback support was a feature introduced inFlash 6.1, so nearly all current Flash-compatible SDKs have theability to support video playback. A Flash application typically consists of two distinct pieces:The animation engine that renders deterministic graphics forthe display and the ActionScript engine that uses input events(time, keyboard, mouse and XML) to make runtime decisionsabout whether animations should be played Flash-internally orexternally. ActionScript is a scripting language based on ECMAS-cript available in three versions. Developing Flash applications, animations or video for mo-bile devices does not differ significantly from developing browserbased Flash applications for desktop computers. However, youmust be aware of the requirements and restrictions of the targetdevice. Programming Flash Apps 35
  44. 44. Be sure to save your Flash files in a format that is compatiblewith your target device’s software. Pay special attention to the design of your Flash application. Adobe CS provides the option to choose between developinga browser-dependent or a standalone Adobe AIR4 application. AnAIR application is essentially a Flash player, browser engine, andthe native device’s APIs wrapped into one executable file, so thatit conforms to the developer terms and security requirementsof various mobile platforms. Alternative Flash-compatible SDKsgo further and integrate Flash content into existing 2D and 3Dsoftware applications. There are also open source versions including Gnash5 andGameSWF6 that are designed for desktop systems. Many of thealternative Flash-compatible platforms run outside the browserenvironment, working directly with a device’s native APIs.Tips And TricksAs it is mentioned often in this guide, it is crucial to consider bat-tery life when creating applications for mobile devices, Flash is noexception. You should never create memory-intensive animationspurely for the sake of offering a fancy effect. A Flash animationusing ActionScript 3 will create a binary that could be more than3 times larger than that for an ActionScript 2 animation and willlikely result in poor performance. In general, you should think carefully about whether you needActionScript 3: It’s a completely different scripting language to4  www.adobe.com/products/air.html5  www.gnashdev.org6  tulrich.com/geekstuff/gameswf.html Programming Flash Apps 36
  45. 45. ActionScript 2 and requires a lot more development know-howand experience to implement efficiently.You might also want to remember the following to avoid yourFlash app causing excessive battery drain:—— Avoid sliding a Flash object across the screen, unless you know it performs well. Redrawing every pixel multiple times in a frame without the support of a GPU is a performance killer. Select a SDK toolkit that minimizes CPU utiliza- tion to preserve battery life. If the Flash animation is not changing, the SDK toolkit should show 0% CPU utilization.—— If the target smartphone has one display resolution, use correctly sized 2D bitmaps to replace SVG objects that will never change size.—— Minimize network connectivity to that which is required only.—— Use OS APIs with care. The greater number of OS APIs and independent software you use, the more work is being done and the faster the battery runs out of power.—— Design the application to recover gracefully from power failures. Many of the alternative Flash-compatible SDKs have additional APIs to support power failures and include database tools that you can implement in an application (for example to save and restore settings). These tools mean your user doesn’t need to re-key data after a power failure. Programming Flash Apps 37
  46. 46. TestingThe best approach for initial testing is determined by yourchosen architecture: If you have developed an Adobe Flashbrowser-based application or Adobe AIR application, then it’sbest to test the application using the Adobe tools. However, if you have developed a Flash animation (with orwithout ActionScript) or Flash animations that will be integratedinto another 2D or 3D application, you should consider test-ing the application with one of the alternative Flash-compatibleSDKs or tools. Adobe CS5 has a built-in smartphone emulator also. This en-ables developers to virtually test their application on selectedhandsets and tablets. In general: Always test on devices to gain information onhow much memory and battery is being used by the application.
  47. 47. Packaging And DistributionWhen you design Flash content for use in a mobile website, pack-aging and distribution is straightforward: You simply follow thesame rules and procedures you would use in deployment for usein a desktop browser. Using Flash in a web widget is similar also. Generally you in-clude the Flash content in the widget as you would for a website,package the widget and deploy the resulting application in linewith the widget environment’s requirements – for more informa-tion see the chapter ”Programming Mobile Widgets”. When the platform offers a built in Flash player that runsFlash content as an application the packaging requirements canbe more complicated. At the simple end of the spectrum is NokiaSeries 40, where the packaging requirements are quite simple7: You create some metadata, an icon and pack these with theFlash content into a zip file with the extension *.nfl. At the complex end of the spectrum is packaging for Symbiandevices, where the Flash app has to be given a Symbian C++launcher and packed in a Symbian SIS file. While some developers will do this manually, Nokia providesan online packaging service that does the heavy lifting for you8. Generally, when the packaging seems complex, it can often besimplified by using the platform’s widget option to package anddeploy the content. In general, once Flash content has been packaged into thecorrect format for the platform, it can then be distributedthrough any app store that services that platform.7  bit.ly/aqEmvv8  esitv008song.itlase.com/sispack Programming Flash Apps 39
  48. 48. Programming iOS AppsiOS, running on the iPhone, iPod touch and iPad, is a very in-teresting and very popular development platform, one commonlystated reason for this being the App Store. When it was intro-duced in July 2008, the App Store took off like no other market-place had before. Now there are more than 500,000 applicationsin the App Store, and the number is growing daily. This reflectsthe success of the concept, but it means that it is getting everharder to stand out in this mass of applications. In December 2011, Apple announced that users have down-loaded more than 18 billion iOS apps. Nearly every quarter devicesales are reaching new all-time highs and there is no sign of aslowdown in the billion downloads per month. Over 200 milliondevices are in the hands of users willing to try apps and pay forcontent, making the App Store one of the most economicallyinteresting targets for mobile app development. The iOS SDK offers high-level APIs for a wide range of tasks,which helps to cut down on development time. New APIs areadded in every major update of iOS for iPhone, such as MapKitin iOS 3.0, (limited) multitasking in iOS 4.0 and Game Center iniOS 4.1. The iPad, which went on sale in April 2010, uses the sameoperating system and APIs as the iPhone, therefore the skills ac-quired in iPhone development can be used in iPad developmenttoo. A single binary can even contain different versions for bothplatforms with large parts of the code being shared. Since therelease of iOS 4.2, in November 2010, all iOS devices sold haveused a common firmware version. This absence of fragmentationmakes it possible to develop universal apps for multiple deviceclasses much more easily than on other mobile platforms. iOS 5.0, released in Q4 2011 includes various new features Programming iOS Apps 40
  49. 49. and over 1,500 new APIs for developers. One of the most inter-esting is iCloud, which provides for easy cloud storage of appli-cation-specific data, documents and easy-to-implement Twitterfunctionality.PrerequisitesApple’s iOS SDKIn order to develop iPhone (and iPod Touch and iPad) apps,you will need the iOS SDK, which can be downloaded atdeveloper.apple.com/iphone. This requires a membership, whichstarts at USD 99/year. If you do not plan on distributing yourapps in the App Store and don’t wish to test your apps on anactual device, you can also download Xcode from the Mac AppStore for free. The iOS SDK contains various applications that will allow youto implement, test, and debug your apps. The most importantapplications are:—— Xcode, the IDE for the iOS SDK—— Interface Builder, to build user interfaces for iPhone app (integrated into Xcode as of Xcode 4.0)—— Instruments, which offers various tools to monitor app execution—— iOS Simulator, which enables you to test apps quickly, rather than deploying them to a device 41
  50. 50. The iOS SDK will work on any Intel-based Mac running Mac OSX 10.6 (Snow Leopard) or 10.7 (Lion, which is the recommendedOS X version). A guide to get you started and introduce you to the tools isincluded in the SDK, as is a viewer application for API documen-tation and sample code. References and guides are also availableonline at developer.apple.com/iphone/library/navigation. The SDK includes a large number of high-level APIs separatedinto a number of frameworks and libraries, which include:—— Cocoa Touch, which consists of the UI libraries, various input methods such as multi-touch and accelerometer.—— Media frameworks, such as OpenAL, OpenGL ES, Quartz, Core Animation and various audio and video libraries—— Core Services, such as networking, SQLite, threading and various other lower level APIs.The list of available frameworks grows with each major releaseof the iOS firmware, which usually happens once a year in Juneor July, with iOS 5.0 being the exception to this rule with itsrelease in October 2011. Programming iOS Apps 42
  51. 51. Alternative Third-Party Development EnvironmentsSince Apple relaxed their App Store distribution guidelines, de-velopment using tools other than Objective-C, Cocoa Touch andXcode is officially permitted again and most commonly used ingame development, for example using the Unreal DevelopmentKit1, which Epic released for iOS to much fanfare in December2010. Using third party development environments and languagesfor iOS development offers a number of advantages and disad-vantages. The major advantage being that it is easy to support mul-tiple platforms from a single code base without having too muchof a maintenance burden. However, as experience with desktopsoftware has shown, cross-platform software development rarelyproduces apps of outstanding quality. In most cases the cross-platform tool concentrates on the lowest common denominatorand the resulting product does not feel like it really belongs onany of the targeted platforms. For an overview on cross-platformtechnologies in general, please see the corresponding chapterin this guide. There are, however, third party development environmentsthat focus solely on iOS development, such as MonoTouch2. This platform enables developers to build iOS apps using C#and .NET while taking advantage of iOS APIs. This makes it thealternative that comes closest to the original SDK, while still al-lowing code re-use, for example when creating similar WindowsPhone 7 apps. Some alternative IDEs carry additional fees, which are in ad-dition to Apple’s yearly development program charge and their30% cut of all sales. Given the drawbacks of cross-platform de-velopment mentioned earlier, using third party IDEs makes the1  www.udk.com2  www.monotouch.net Programming iOS Apps 43
  52. 52. most sense for games, which can share almost all their codebetween different platforms. Java IDE makers JetBrains recentlyreleased an Objective-C IDE of their own, called AppCode, whichis still in beta stage but looks as if it provides some advancedfeatures.ImplementationUsually, you will want to use Apple’s high-level Cocoa Touch APIswhen developing for the iPhone. This means that you will writeObjective-C code and create your user interfaces in InterfaceBuilder, which uses the proprietary XIB file format. Objective-C is, as the name suggests, a C-based object-ori-ented programming language. As a strict superset of C, it is fullycompatible with C, which means that you can use straight Csource code in your Objective-C files. If you are used to other object-oriented languages such asC++ or Java, Objective-C’s syntax might take some time gettingused to, but is explained in detail at developer.apple.com3. Whatseparates Objective-C most from these languages is its dynamicnature, lack of namespace support and the concept of messagepassing vs. method calls. A great way to get you started is Apple’s guide “Your FirstiPhone Application”, which will explain various concepts andcommon tasks in an iPhone developer’s workflow4. Also checkout some of the sample code that Apple provides online5 to findout more about various APIs available to you.3  developer.apple.com/iphone/manage/overview/index.action4  developer.apple.com/iphone/manage/distribution/distribution.action5  developer.apple.com/iphone/library/navigation/SampleCode.htm Programming iOS Apps 44
  53. 53. TestingAs performance in the iPhone Simulator can be superior to theperformance on a device, it is absolutely vital that testing iscarried out on devices. It is highly recommended that you haveat least one example of each class of device you want to deployyour apps on. For example, an iPhone-only app shouldn’t need to be testedseparately on an iPad. However, it cannot hurt to have severalclasses of device, including older models, since problems suchas excessive memory consumption sometimes will not presentthemselves on newer hardware. Testing on real devices is also important because touch-basedinput is completely different from the pointer–driven UI model. End-user testing can be achieved by distributing builds of theapplication to as many as 100 testers, through Ad-Hoc Provision-ing, which you can set up in the Program Portal6. Each iPhone(and iPad/ iPod touch) has a unique identifier (UDID – universaldevice identifier), which is a string of 40 hex characters basedon various hardware parts of the device. If you choose to test using Ad-Hoc-Provisioning, simply fol-low Apple’s detailed set-up instructions7. Every single step is vi-tal to success, so make sure that you execute them all correctly. With iOS 4.0, Apple has introduced the option for developersto deploy Over-The-Air (OTA) Ad-Hoc builds of their apps to betatesters. There are open source projects8 to facilitate this newfeature, as well as commercial services9.6  developer.apple.com/iphone/library/referencelibrary/GettingStarted/ Learning_Objective-C_A_Primer/index.html#//apple_ref/doc/uid/ TP400075947  developer.apple.com/iphone/library/documentation/iPhone/Conceptual/ iPhone101/Articles/00_Introduction.html8  github.com/therealkerni/hockeykit9  www.testflightapp.com Programming iOS Apps 45
  54. 54. Google Toolbox for Mac10 runs test cases using a shell scriptduring the build phase, while GHUnit11 runs the tests on thedevice (or in the simulator), allowing the developer to attacha debugger to investigate possible bugs. Version 2.2 of the SDKApple included OCUnit; an example of how to create the unittests is available online12. In iOS 4.0 Apple introduced a new tool, UIAutomation thataims to automate the testing of your application by scriptingtouch events. UIAutomation tests are written in JavaScript and afull reference is available in the iOS Reference Library13. Severalother third party testing automation tools for iPhone applica-tions are available, including FoneMonkey14 and Squish15.DistributionIn order to reach the broadest possible audience, you shouldconsider distributing your app on the App Store. There are othermeans, such as the Cydia Store for jailbroken iOS devices, but thepotential reach isn’t nearly as large as the App Store’s. To prepare your app for the App Store, you will need a 512x512version of your app’s icon, up to five screen shots of your app,and a properly signed build of your app. Log in to iTunes Con-nect and upload your app according to the onscreen instructions. After Apple has approved your application, which usuallyshouldn’t take more than 2 weeks, your app will be available tocustomers in the App Store. Due to past app submission rejec-tions, the approval process receives more complaints than any10  code.google.com/p/google-toolbox-for-mac11  github.com/gabriel/gh-unit12  www.mobileorchard.com/ocunit-integrated-unit-testing-in-xcode13  developer.apple.com/library/ios/#documentation/DeveloperTools/Reference/ UIAutomationRef/_index.html14  www.gorillalogic.com/fonemonkey15  www.froglogic.com/products Programming iOS Apps 46
  55. 55. other aspect of the iPhone ecosystem. A list of common rejectionreasons can be found on www.apprejections.com. Recently, Applehas released their full App Store testing guidelines in order togive developers a better chance to evaluate their app’s likelihoodof being approved. Also, the restrictions have been relaxed andapps that were previously rejected have been approved after be-ing resubmitted. Approximate review times as experienced recently by otherdevelopers are gathered at reviewtimes.shinydevelopment.com foryour information. However, there is no guarantee that an appwill be approved in the timeframe specified on the site. Thisshould be used as a guideline only.BooksA number of great books have been written on iOS development.Here is a short list, which is by no means complete, of goodtutorials and references:Beginner booksThese books are best for someone looking into getting startedwith iOS development.—— iPhone SDK Development by Bill Dudney and Chris Adam- son—— Beginning iPhone 3 Development by Dave Mark & Jeff LaMarche Programming iOS Apps 47
  56. 56. Intermediate booksBooks suited for those who have had some exposure to the iOSSDK and are looking to deepen their knowledge of the platform.—— More iPhone 3 Development by Dave Mark and Jeff LaMarche—— Programming in Objective-C 2.0 by Stephen KochanProfessional booksIf you already have some good knowledge of the iOS SDK, one ofthese books is sure to increase your skill set.—— Cocoa Design Patterns by Erik M. Buck and Donald A. Yacktman—— Core Data by Marcus ZarraCompanion booksBooks that every aspiring iOS developer should call their ownbecause they impart knowledge besides programming, such asthe importance of user experience using case studies and per-sonal experiences.—— Tapworthy by Josh Clark—— App Savvy by Ken Yarmosh Programming iOS Apps 48
  57. 57. CommunityOne of the most important aspects of iOS development is thecommunity. Many iOS developers are very forthcoming and openabout what they do, and how they did certain things. This activity has become even more visible as Twitter andGithub have gained momentum and become widely-known. Search for iPhone, iPad or any other related search terms onGithub.com and you’ll find a lot of source code, frameworks, tu-torials, code snippets and complete applications – most of themwith very liberal licenses that even allow for commercial use. Practically all of the most important and most experiencediOS developers use Twitter to share their thoughts about theplatform. There are many comprehensive lists of iOS developersavailable, a notable and well-curated one being Robert Scoble’slist16. Following such a list helps you stay up to date on cur-rent issues and interesting information about iOS developmentgenerally. What makes the community especially interesting isthat many iOS developers pride themselves on taking an excep-tional interest in usability, great user experience and beauti-ful user interfaces. You can usually find out about the most in-teresting trends on blog aggregators such as CocoaHub.de andPlanetCocoa.org.16  www.twitter.com/Scobleizer/iphone-and-ipad
  58. 58. ProgrammingJ2ME / Java ME AppsJ2ME (or Java ME as it is officially called) is the world’s mostwidespread mobile application platform and the oldest one stillwidely used. Developed by Sun Microsystems, which has sincebeen bought by Oracle, J2ME is designed to run primarily on fea-ture phones. It has been very successful in this market segment,with an overwhelming majority of feature phones supportingit. J2ME is also supported natively on Symbian and BlackBerrysmartphones. J2ME’s major drawback is that, due to its age and primarymarket segment, it doesn’t fare all that well compared to moremodern platforms, such as Android, iPhone, BlackBerry and Sym-bian: it offers a less powerful set of APIs, often runs on lesspowerful hardware and tends to generate less money for the de-veloper. As a consequence, J2ME’s popularity in the developercommunity has declined significantly in recent years, in favor ofdevelopment on smartphone platforms. So why would you want to develop for J2ME? Mainly for onereason: market reach. With over 70% of phones worldwide supporting it, J2ME ismiles ahead of the competition in this regard. In late 2011,J2ME even overtook Android when it comes to mobile browsing:While most of mobile browsing was done on iOS devices (51%),J2ME was on position two with 21%. Only 16% of the mobileweb users had an Android device1. So if your business modelrelies on access to as many potential customers as possible, oron providing extra value to existing customers via a mobile ap-plication, then J2ME might still be a great choice.1  www.netmarketshare.com Programming J2ME / Java ME Apps 50
  59. 59. However, if your business model relies on direct applicationsales, or if your application needs to make use of state-of-the-art features and hardware, you might want to consider target-ing a different platform (such as Android, BlackBerry, iPhone orSymbian). That being said, it should be noted that Java ME’s capabilitiesare constantly improving thanks to the Java Community Processthat standardizes new APIs: for example, modern features suchas GPS, sensors, 3D graphics and touchscreens are all supportedby the platform today. In addition, J2ME-compatible hardwareis becoming more powerful and less expensive all the time, andwith more and more devices implementing the advanced featuresmentioned. Overall the platform is evolving and changing for thebetter, though admittedly at a considerably slower pace com-pared to the competition.PrerequisitesTo develop a Java ME application, you will need:—— The Java SDK2 (not the Java Runtime Environment) and an IDE of your choice, such as Eclipse Pulsar for Mobile Devel- opers3, NetBeans4 with its Java ME plug-in or IntelliJ5.—— An emulator, such as the Wireless Toolkit6, the Micro Emu- lator7 or a vendor specific SDK or emulator.2  www.oracle.com/technetwork/java/javame/downloads/index.html3  www.eclipse.org4  www.netbeans.org5  www.jetbrains.com6  www.oracle.com/technetwork/java/download-135801.html7  www.microemu.org Programming J2ME / Java ME Apps 51
  60. 60. —— Depending on your setup you may need an obfuscator like ProGuard8. If you build applications professionally you will probably want to use a build tool such as Maven9 or Ant10 also.—— You may want to check out J2ME Polish, the open source framework for building your application for various de- vices11. Complete installation and setup instructions are beyond thescope of this guide, please refer to the respective tools’ docu-mentation. Beginners often like to use NetBeans, with the JavaME plug-in installed. Also download and read the JavaDocs forthe most important technologies and APIs: You can downloadmost Java-Docs from www.jcp.org. There are a couple of usefulvendor specific APIs that should be tracked down manually fromthe vendor’s pages (such as the Nokia UI API and Samsung APIs).8  www.proguard.sourceforge.net9  maven.apache.org10  ant.apache.org11  www.j2mepolish.org
  61. 61. ImplementationThe Java ME platform is fairly straight-forward: it comprisesthe Connected Limited Device Configuration (CLDC)12 and theMobile Internet Device Profile (MIDP)13,both are quite easy tounderstand. These form the basis of any J2ME environment andprovide a standardized set of capabilities to all J2ME devices. Asboth CLDC and MIDP were designed a decade ago, the default setof capabilities they provide is rudimentary by today’s standards. Manufactures can supplement these rudimentary capabilitiesby implementing various optional Java Specification Requests(JSRs). JSRs exist for everything from accessing the device’sbuilt in calendar, address book and file system (JSR 75); to usingthe GPS (JSR 179) and Near Field Communication (JSR 257). Fora comprehensive list of JSRs related to Java ME development,visit the Java Community Process’ “List by JCP Technology”14. It is very important to remember that not all JSRs are avail-able on all devices, so capabilities available on one device mightnot be available on another device, even if the two devices havesimilar hardware.The Runtime EnvironmentJ2ME applications are called MIDlets. A MIDlet’s lifecycle is quitesimple: it can only be started, paused and destroyed. On mostdevices, a MIDlet is automatically paused when minimized; itcannot run in the background. Some devices support concurrent12  java.sun.com/products/cldc/overview.html13  java.sun.com/products/midp/overview.html14  www.jcp.org/en/jsr/tech?listBy=1&listByType=platform Programming J2ME / Java ME Apps 53
  62. 62. application execution, so it is possible for applications to runin the background. However, this usually requires the use ofvendor-specific APIs and/or relies on device-specific behavior,which can cause fragmentation issues. MIDlets also run in isolation from one another and are verylimited in their interaction with the underlying operating sys-tem – these capabilities are provided strictly through optionalJSRs (for example, JSR 75) and vendor-specific APIs.Creating UIsYou can create the UI of your app in several ways: 1. Highlevel LCDUI components: you use standard UI com- ponents, such as Form and List 2. Lowlevel LCDUI: you manually control every pixel of your UI using low-level graphics functions 3. SVG: you draw the UI in scalable vector graphics then use the APIs of JSR 226 or JSR 28715.In addition, you will find that some manufacturers provide ad-ditional UI features. For example, Nokia recently introduced theTouch and Type UI to its Series 40 platform. To enable develop-ers to make best use of this UI in their applications, the NokiaUI API was extended to provide features to capture screen ges-tures and provide controlling data for UI animations. SimilarlySamsung provide pinch zoom features in their latest Java MEAPIs. There are also tools that can help you with the UI develop-ment. All of them use low-level graphics to create better lookingand more powerful UIs than are possible with the standard high-level LCDUI components.15  www.jcp.org/en/jsr/detail?id=287 Programming J2ME / Java ME Apps 54
  63. 63. 1. J2ME Polish16: This tool separates the design in CSS and you can use HTML for the user interface. It is backward- compatible with the highlevel LCDUI framework 2. LWUIT17: A Swing inspired UI framework 3. Mewt18: Uses XML to define the UI One very important aspect to consider when designing your UIis the typical screen resolution for Java ME devices. The vast ma-jority of Java ME devices have one of the following resolutions:240x320, 176x208, 176x220, 128x160, 128x128 or 360x640pixels. By far the most popular is 240x320, while 360x640 is acommon resolution for high-end Java ME devices (typically thoserunning Symbian or Blackberry) and 176x208/220 is a commonresolution for low-end devices. You will also encounter devicesthat have these resolutions in landscape, for example 320x240instead of 240x320 pixels. Handling so many different resolutions can be a challenge.Your best approach is to create UI layouts that can scale wellacross all of them, in the same way that web pages scale wellacross different browser window sizes. You can also create cus-tom UIs for each resolution, though this is not recommendedbecause it is time consuming, error prone and expensive. Another aspect worth considering is the size of your applica-tion’s assets, especially its graphical assets. Whenever possible,your assets should be optimized, in order to keep your applica-16  www.j2mepolish.org17  lwuit.dev.java.net18  www.mewt.sourceforge.net 55
  64. 64. tion’s size as small as possible. This results in cheaper downloadsfor your users (as less data traffic is needed) and greater marketreach (as some devices have a limit on the maximum applicationsize). A great free tool for this is PNGGauntlet19, which can opti-mize your graphical assets without compromising quality. Despite the platform’s limitations, it is quite possible to cre-ate great looking and easy to use Java ME user interfaces, par-ticularly if one of the tools mentioned above is used.Open SourceThere is a rich open source scene in the J2ME sector. Interest-ing projects can be found via the blog on opensource.ngphone.com. You will also find fascinating projects on the Mobile andEmbedded page of java.net20, for example the Bluetooth projectMarge21.TestingBecause of the fragmentation in the various implementations ofJava ME, testing applications is vital. Test as early and as oftenas you can on a mix of devices. Some emulators are quite good(personal favorites are BlackBerry and Symbian), but there aresome things that have to be tested on devices. Thankfully, vendors like Nokia22 and Samsung23 provide subsi-dized or even free remote access to selected devices.19  www.pnggauntlet.com20  mobileandembedded.dev.java.net21  marge.dev.java.net22  www.forum.nokia.com/rda23  innovator.samsungmobile.com Programming J2ME / Java ME Apps 56
  65. 65. Automated TestingThere are various unit testing frameworks available for Java ME,including J2MEUnit24, MoMEUnit25 and CLDC Unit26; System andUI testing is more complex given the security model of J2ME,however JInjector27 is a flexible byte-code injection frameworkthat supports system and UI testing. Code coverage can also begathered with JInjector.PortingOne of the strengths of the Java environment for mobile devicesis that it is backed by a standard, so it can be implemented bycompeting vendors. The downside is that the standard has tobe interpreted, and this interpretation process can cause differ-ences in individual implementations. This results in all kinds ofbugs and non-standard behavior. In the following sections weoutline different strategies for porting your applications to allJava ME handsets and platforms.Direct SupportThe best but hardest solution is to code directly for differentdevices and platforms. So you create a J2ME app for MIDPdevices, a native BlackBerry app, a native Windows Mobile app,a Symbian app, an iPhone app, a Web OS app, and so on. As youcan imagine, this approach has the potential to bring the verybest user experience, since you can adapt your application toeach platform’s UI. At the same time your development costs willskyrocket. We advise the use of another strategy first, until yourapplication idea has proved itself to be successful.24  www.j2meunit.sourceforge.net25  www.momeunit.sourceforge.net26  snapshot.pyx4me.com/pyx4me-cldcunit27  www.code.google.com/p/jinjector Programming J2ME / Java ME Apps 57
  66. 66. Lowest Common DenominatorYou can prevent many porting issues by limiting the functional-ity of your application to the lowest common denominator. Inthe J2ME world this usually means CLDC 1.0 and MIDP 1.0. If youonly plan to release your application in more developed coun-tries/ regions, you may consider targeting CLDC 1.1 and MIDP2.0 as the lowest common denominator (without any additionalAPIs or JSR support). Depending on the target region for the application you mightalso consider using Java Technology for the Wireless Industry(JTWI, JSR 185) or the Mobile Service Architecture (MSA, JSR248) as your baseline. Both extensions are designed to ensurea common implementation of the most popular JSRs. They aresupported by many modern devices and provide many more ca-pabilities to your applications. However, in some regions suchas Africa, South America or India you should be aware that us-ing these standards may limit the number of your potential us-ers, because the more common handsets in these regions do notimplement those extensions. Using the lowest common denominator approach is typicallyeasy: There is less functionality to consider. However, the userexperience may suffer if your application is limited in this way,especially if you want to port your application to smartphoneplatforms later. So this approach is a good choice for simple ap-plications – for comprehensive, feature-rich applications it maynot be the way to go.Porting FrameworksPorting frameworks help you deal with fragmentation by au-tomatically adapting your application to different devices andplatforms. Such frameworks typically feature the followingcomponents: Programming J2ME / Java ME Apps 58
  67. 67. —— Client libraries that simplify development—— Build tool chains that convert code and resources to ap- plication bundles—— Device databases that provide information about devices—— Cross compilers to port your application to different plat- formsFor Java ME some of the options you can choose from are: Celsius from Mobile Distillery28 that is licensed per month,Bedrock from Metismo29 that provides a suite of cross compilerson a yearly license fee and J2ME Polish from Enough Software30that is available under both the GPL Open Source license and acommercial license. Going in the other direction (from C++ toJava ME) is also possible with the open source MoSync SDK31. For more information about cross-platform development andthe available toolsets, please see the “Programming With Cross-Platform Tools” chapter. Good frameworks enable you to use platform and device spe-cific code in your projects, so that you can provide the best userexperience. In other words: a good porting framework does nothide device fragmentation, but makes the fragmentation moremanageable.SigningThe Java standard for mobile devices differentiates betweensigned and unsigned applications. Some handset functionalityis available to trusted applications only. Which features are af-fected and what happens if the application is not signed but28  www.mobile-distillery.com29  www.metismo.com30  www.enough.de31  www.mosync.com Programming J2ME / Java ME Apps 59
  68. 68. uses one of those features, is largely dependent on the imple-mentation. On one phone the user might be asked once to enable thefunctionality, on another they will be asked every time the fea-ture is used and on a third device they will not be able to use thefeature at all without signing. Most implementations also dif-ferentiate between the certification authorities who have signedan application. Applications signed by the manufacturer of a device enjoy thehighest security level and can access every Java API availableon the handset. Applications signed with a carrier certificate aresimilarly trusted. Applications signed by JavaVerified32, Verisign33 or Thawte34are on the lowest security level. To make matters worse, notevery phone carries all the necessary root certificates. And, inthe past, some well known device vendors have even strippedaway all root certificates. The result is something of a mess, soconsider signing your application only when required, that iswhen deploying to an app store or when you absolutely needaccess to security constrained features. However, in some casesan app store may offer to undertake the signing for you, as NokiaStore does. Another option is to consider using a testing and certi-fication service provider and leaving the complexity to them.Intertek35 is probably the largest such supplier.DistributionJ2ME applications can be installed directly onto a phone ina variety of ways; the most commonly used methods are overa Bluetooth connection, via a direct cable connection or Over- 32  www.javaverified.com 33  www.verisign.com 34  www.thawte.com 35  www.intertek.com/wireless-mobile 60
  69. 69. the-Air (OTA). However, app stores are probably the most ef-ficient way to distribute your apps.: They manage the payment,hosting and advertisements, taking a revenue share for thoseservices. Some of the most effective stores include:—— Handmark36 and Mobile Rated37 provide carrier and vendor independent application stores.—— GetJar38 is one of the oldest distributors for free mobile applications – not only Java applications.—— LG distributes apps on www.lgapplication.com—— Nokia Store39 targets Nokia users worldwide and provides a revenue share to the developer at 70% from credit card billing and 60% from operator billing—— Carriers are in the game also, such as Orange40 and O241.Basically almost everyone in the mobile arena has announcedan app store. An overview of the available app stores (not thoseselling J2ME apps alone) can be found in the WIP App StoreCatalogue42. Furthermore there are various vendors who providesolutions for provisioning of Java applications over a Bluetoothconnection, including Waymedia43 and Futurlink44.36  store.handmark.com37  www.mobilerated.com38  www.getjar.com39  www.publish.ovi.com40  http://bit.ly/A3Dde041  www.o2litmus.com42  www.wipconnector.com/appstores/43  www.waymedia.it44  www.futurlink.com 61
  70. 70. Programming Qt AppsPronounced “cute” – not “que-tee” – Qt is an application frame-work that is used to create desktop applications and even awhole desktop environment for Linux – the KDE Software Com-pilation. The reason many developers have used Qt for desktopapps, is that it frees them from having to consider the underly-ing platform – a single Qt codeline can be compiled to run onMicrosoft Windows, Apple Mac, and Linux. When Nokia acquired Trolltech – the company behind Qt – itwas with the goal of bringing this same ease of developmentfor multiple platforms to Nokia mobile phones. Today, Qt can beused to create applications for phones based on Symbian and theNokia N9 smartphone. In fact, Qt can now be thought of as a platform in its ownright – you can create a Qt application and deploy it to phonesutilizing a number of different underlying operating systems. Inthe future, Qt will underpin Nokia’s next billion strategy. The challenge when developing with C and C++ is that theselanguages place all the responsibility on you, the developer. Forexample, if you make use of memory to store some data in yourapplication, you have to remove that data and free the memorywhen it is no longer needed (if this is not done, the dreadedmemory leak occurs). Qt uses standard C++ but makes extensive use of a special pre-processor (called the Meta Object Compiler, or moc) to deal withmany of the challenges faced in standard C++ development. Asa consequence Qt is able to offer powerful features that are notburdened by the usual C++ housekeeping. For example, insteadof callbacks, a paradigm of signals and slots is used to simplify Programming Qt Apps 62
  71. 71. communication between objects1; the output from one objectis a “signal” that has a receiving “slot” function in the same oranother object. Adding Qt features to an object is simply a case of includingQObject (which is achieved by adding the Q_OBJECT macro tothe beginning of your class). This meta-object adds all the Qtspecific features to an object. Qt then provides a range of ob-jects for realizing GUIs created using Qt Quick, building complexgraphical views (the QGraphicView object), managing networkconnections and communications, using SVG, parsing XML, andusing scripts among others. Many developers who have used Qt report that applicationscan be written with fewer lines of code and with greater in-builtreliability when compared to coding from scratch in C++. As aresult less time is needed to create an application and less timeis spent in testing and debugging. For mobile developers using Qt is free of cost. It benefits frombeing open source also, with a large community of developerscontributing to the content and quality of the Qt APIs. Shouldyou wish to get involved in developing Qt, you can do so throughthe Qt Project2.1  doc.qt.nokia.com/4.7-snapshot/signalsandslots.html2  qt-project.org/
  72. 72. PrerequisitesQt SDK3 installs everything you need to create, test, and debugapplications for Symbian phones and the Nokia N9 smartphone,as well as desktop applications, from a single package.All versions offer tools for compiling Symbian and Nokia N9 apps,with Symbian apps being compiled in the Linux and Apple Macversions using the Remote Compiler service.Creating Your ApplicationQt SDK is built around the Qt Creator development tool. UsingQt Creator you define most of your application visually and thenadd the specific program logic through a code editor, which of-fers full code completion support and integrated help. One of theneat features of Qt is Qt Quick4, a comprehensive solution fordeclarative UI definition. Qt Quick uses QML, a language similarto JavaScript’ to define the UI; but also provides Qt Quick Com-ponents – a set of predefined UI components that match the UIstyle seen on the latest Symbian phone and the Nokia N9 – thatfurther speed up UI development. While Qt Quick generally simplifies UI development, one ofits biggest advantages is that the tools within Qt Creator enablethe UI to be defined by graphic designers who do not have to beaware of the technical programming aspects. In the past, one of the challenges with cross platform applica-tions for mobile has been accessing platform features: Anytime3  developer.nokia.com/Develop/Qt/Tools4  qt.nokia.com/qtquick/ Programming Qt Apps 64

×