Introduction to Phone Gap

The mobile landscape is littered with devices, platforms, and operating systems. If you are a web developer, you might be familiar with the agony of testing 10 or so browser versions across 10 or so operating system versions. Multiply that by 100 and you have mobile. There is simply no cost-effective way to develop and test across all of the possible combinations.

Enter PhoneGap. PhoneGap is an open source development tool created by Nitobi that acts as a unified bridge between web apps and mobile devices. It essentially consists of a native app project template for each of the major platforms, where each project is just a chromeless web browser with heightened permissions. What this means in concrete terms is that PhoneGap makes it possible to add a single snippet of JavaScript to your web app that will give you access to the camera on an iPhone, a Nexus One, a Palm Pre, and others.

Furthermore, the resulting app—although written by you with HTML, CSS, and JavaScript—is encased in a native app and you can submit it to the respective app store for the platforms in question. Currently, iPhone, Android, BlackBerry, Palm, Symbian (Nokia), and Windows Mobile are supported, and Windows Phone 7 is in development.

Of course, different devices have different features. Maybe a particular device doesn't have a camera or doesn't have an accelerometer. Even when devices do have the same features, they each have their own ways of exposing these features to the developer. PhoneGap abstracts the APIs for the most widely available mobile phone features so mobile application developers can use the same code everywhere. You still need to deploy your app manually using the SDK (Software Development Kit) provided by the vendor, but you don't need to change your application code.

* > There are other projects and products available that serve a similar purpose as PhoneGap, such as RhoMobile and Titanium Mobile, but I ' ' | $ prefer PhoneGap because it allows you to write a standard web app and drop it into a native code environment virtually unchanged.

Every other product that I've looked at requires you to write code based on a proprietary framework that only outputs native code (i.e., you aren't writing HTML, CSS, and JavaScript that would run in a browser). I'm not familiar enough with them to do an in-depth comparison, so you might want to check them out in case one suits your needs better than PhoneGap.

Since this is an Android book, we'll focus on the Android branch of PhoneGap. Just be aware of the fact that you could potentially deploy your app to iPhone, Nokia, Palm, and other popular devices with little or no modification.

Using the Command Line

In this chapter, we'll be interacting with PhoneGap and the Android SDK via the command line. The command line is a text-only environment that allows you to do things that you can't do through the operating system's normal graphical UI. On Mac OS X, this is the Terminal application, which lives in the /Applications/Utility folder. On Windows, it's the command prompt (click the Start Menu, choose All Programs^ Accessories^Command Prompt). On Linux, open an xterm or Terminal.

The command line can seem pretty geeky and cryptic at first, so I promise to keep things to a bare minimum and explain everything as much as possible along the way. As you work through the examples, be sure to type things exactly as you see them here. In other words, spaces and capitalization count. You can also download the sample files for this chapter from the O'Reilly page for this book if you'd prefer to copy and paste.

Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide


Post a comment