Android logo
Creating a Native Android App
Two versions of PhoneGap are currently available: PhoneGap and PhoneGap Build.
The full version of PhoneGap is a downloadable framework that works with the APIs and Software Development Kits (SDKs) for the various supported platforms to generate native apps from HTML5 Web apps. To use PhoneGap, you first need to set up your computer as if you were going to develop native apps.
In the case of iOS apps, this means that you need to enroll in the Apple Developer program and pay $99 per year. I won't require you to become an Apple developer for this course, but if you're interested in finding out more, I've put a link in the Supplementary Material.
If you want to develop Android apps, you can simply download the Android SDK using the link in the Supplementary Material.
You can download other native app development kits from the websites of the operating system creator. Besides iOS and Android, PhoneGap can also build native apps for BlackBerry, Windows Phone, webOS (which Palm created and then HP acquired), and Symbian (used on some Nokia phones). Realistically, your app can reach the vast majority of smart phone users by targeting iOS, Android, BlackBerry, and Windows Phone. HP discontinued the development of webOS devices, and Nokia is phasing out Symbian in favor of Windows Phone.
Each of these operating systems has a fundamentally different way of creating native apps. If you decide to go this route for converting your HTML5 apps to native ones, you'll quickly understand why the "write once, deploy anywhere" approach of HTML5 apps is catching on so quickly.
If you don't have the patience for installing SDKs and learning to use each manufacturer's way of developing apps, don't worry about it. PhoneGap has a much easier way of converting your HTML5 apps to native ones, which I'm going to tell you about shortly.
Once you've installed an SDK, the difficult part is done. The next steps are to download the latest version of PhoneGap and then install the version or versions that you'll be creating apps for.
The following figure shows what the PhoneGap framework looks like after you've downloaded and unzipped it:
The unzipped PhoneGap files
Installing an SDK and configuring PhoneGap is beyond the scope of this course, but you can find out exactly what to do by visiting the PhoneGap wiki, which I've linked to in the Supplementary Material.
The downloadable version of PhoneGap gives you the most flexibility in terms of customizing your app. However, if you just want to get something built quickly to see if it works, you can use PhoneGap Build, which is PhoneGap's online service.
Using PhoneGap Build
This service makes creating apps almost as easy as uploading files to a website and clicking a button. While it doesn't give you as much control over how your app is built as you'll get when you download and install the full version, PhoneGap Build is great for getting a taste of the power of converting Web apps into native ones.
In this chapter, I'll take you through the steps to convert WatzThis into native apps for different mobile operating systems.
Before you can upload the app to PhoneGap, you need to package it as a Zip file. If you know how to create a Zip file, go ahead and zip up the latest version of WatzThis, along with all of its supporting files, and name the file watzthis.zip.
If you'd rather have me do the work, you can download watzthis.zipOpens in new window.
Now you're ready to generate your native apps.
- Go to Adobe PhoneGap BuildOpens in new window
- Click the Get Started button.
Get started!
- Choose the Free Plan by pressing Completely Free.
- You'll be given the choice of registering with an Adobe ID or with Github. Click on with Adobe ID.
- If you have an Adobe ID already, you can use the Adobe ID login form to log in.
Your sign-in options
- If you don't have an Adobe ID, click Create an Adobe ID. You'll see a form for creating one.
Creating an Adobe ID if you don't already have one
- Once you're logged in, you'll see the Welcome page.
- Click Upload a .zip file, and locate watzthis.zip on your computer.
Upload your Zip file here.
- After you upload the Zip file, you'll see the following screen. Click Ready to build.
Ready to build!
- Phonegap will start to build your native apps. The next screen shows the status of each of the native apps you're building.
We're waiting on our apps!
Within a couple of minutes, if all goes well, the waiting icons will all change to icons indicating that the app is finished—all except the iOS one. Remember how I mentioned that you had to pay a $99 fee to build native iOS apps? Yup, that's what's going on here.
If you have an Android, webOS, Windows Mobile, Symbian, or BlackBerry phone, you can browse to your PhoneGap Build account with your phone and download the native app. Once it's on your phone, you can install it and run it like any other app.
Don't have a smartphone? I've included a link in the Supplementary Material to instructions that will allow you to install and run the Android Emulator.
Here's what WatzThis looks like as a native app in Android:
WatzThis native Android app
The popup that appears is triggered by our new native compass code, and it indicates the current direction that the device is pointed, as a number between 0 and 359 (representing each degree of the compass). This picture of a compass will help you figure out how the degree numbers correspond to compass directions.
So in the image that says "Heading: 210," you can tell that the smartphone was facing southwest to south-southwest.
Please move ahead to finish this lesson!
Note: Portions of this page are reproduced from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.