Cover by Raffaele Cecco

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

Chapter 10. Creating Android Apps with PhoneGap

In the previous chapter, we developed a mobile-friendly web application using jQuery Mobile. In this chapter, we’ll convert the very same mobile application into a native Android mobile application using PhoneGap. At first glance, converting a humble JavaScript application into a native Android application seems like a miraculous metamorphosis: native Android apps are usually written in Java, Java is not JavaScript, and you can’t convert from one to the other. How does PhoneGap manage this? In fact, PhoneGap’s apparent magical abilities lie within the Android system itself. Android provides a facility called WebView that allows native applications to display regular web content. This includes the ability to execute JavaScript within the web content as normal.

One exciting feature of WebView is that it also allows interaction between a native Android application and the web content within the WebView. This is extremely useful, both for Android developers wanting to display and interact with web content within their applications and for web developers wanting to take advantage of Android device features like cameras and accelerometers. Essentially, PhoneGap is an Android application that uses a WebView for your web content, and also provides a JavaScript library for accessing some of the facilities of the Android device itself.

Other flavors of PhoneGap work in a similar way. For example, the Apple iPhone version of PhoneGap uses the iOS ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required