PhoneGap and Dojo Mobile on Android

Everywhere you go, people are using mobile devices to keep in touch with family and friends, take a picture to post on a social website, find the location of a restaurant, or check the latest news headlines. Mobile devices come in many different shapes and styles. Mobile phones run a variety of different operating systems such as Apple’s iOS, Google’s Android, and Research In Motion’s Blackberry. Some have large displays, physical keyboards, and run on 3G, 4G, or WiFi networks. Mobile phones may also have sensors for acceleration, location, or even payments. Some of these devices aren’t even phones; they’re tablets with larger displays and a data-only network connection.

Despite their differences, mobile devices are similar in that they all run mobile applications. Mobile applications can be divided into two types:

Native applications
Installed on the device, native applications are binary executable programs created using a software development kit (SDK) and distributed through an app store. There is an SDK for each mobile operating system, which unfortunately is different from the SDKs of other operating systems.For example, to create an application for iOS, you must download and install the iOS SDK and development tools, and you must code your application using the Objective-C programming language. An Android application is developed using the Android SDK and written in Java. Thus, to create a mobile application, you must learn each SDK and write your application using the supported programming language. There’s a steep learning curve for each platform’s SDK, so mobile application development is quite complex.
Web applications
Loaded into the mobile web browser, web applications are different from native applications in that they’re coded using web technologies (HTML, JavaScript, and CSS) regardless of the device’s operating system. There’s no need to learn different programming languages for each device. HTML and JavaScript are familiar to web developers since they’re used to create web pages loaded into your desktop browser. For the most part, mobile browsers can render the same web page, but websites often provide a mobile version that has less content and loads faster (due to a smaller screen size and slower network connection).To “run” a web application, the user enters a URL into the mobile web browser. This loads the web page, which is the entry point into a web application. Web applications are not distributed through an app store; they are simply links that can be included in other web pages, e-mails, or even hard copy.

Native and web applications both have advantages and disadvantages, and many arguments have been waged over which is better. In an effort to resolve this battle, a new hybrid application tries to combine the advantages from both native and web applications.

Hybrid applications are programmed using web technologies, like web applications, but are packaged as a native application. A hybrid application can be written once for multiple device operating systems using a programming language familiar to many developers. Since a hybrid application is really a native application, you have access to device features from JavaScript that are not currently available to web applications. Hybrid applications can also be distributed and installed using app stores, just like a native application.

PhoneGap is a popular toolkit for building hybrid applications. It’s an open source mobile framework that includes a JavaScript API for access to device features, such as the accelerometer and camera.

This article shows you how to develop a hybrid mobile Android application using the PhoneGap and Dojo Mobile toolkits. Learn how to use the Android emulator and tools for testing applications, and see how to run your application on an Android device or tablet.

Prerequisites

This article assumes you have some familiarity with the Eclipse development environment, HTML, JavaScript, and CSS. The following software is required:

  • Windows, OSX, or Linux operating system
  • Java Development Kit (JDK) 5 or JDK 6 (a JRE is not sufficient)
  • An Eclipse development environment, such as Eclipse Helios V3.6 or later, or IBM Rational Application Developer V8
  • Android SDK and platforms (r12 or later)
  • Android Development Toolkit (ADT) plugin for Eclipse
  • PhoneGap SDK (V1.0.0 or later)
  • Dojo Toolkit (V1.6 or later)