Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
PhoneGap Beginners Guide (third edition)

You're reading from   PhoneGap Beginners Guide (third edition) Create, develop, debug, and deploy your very own mobile applications with PhoneGap

Arrow left icon
Product type Paperback
Published in Jul 2015
Publisher
ISBN-13 9781784392284
Length 284 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Table of Contents (16) Chapters Close

Preface 1. Introduction to PhoneGap FREE CHAPTER 2. Building Your First PhoneGap Project 3. Mobile Frameworks 4. Working with Plugins 5. Using Device Storage and the Files API 6. Using the Contacts and Camera APIs 7. Accessing the Device Sensors and Locations API 8. Advanced PhoneGap 9. Getting Ready for Release 10. A Sample PhoneGap Project A. The JavaScript Quick Cheat Sheet B. Publishing Your App C. Related Plugin Resources D. PhoneGap Tools Index

Time for action – setting up Android using PhoneGap 3.x

Get ready to set up the Android development environment and create a PhoneGap app using Android as the target platform. In the previous section, we saw how to create a new project. Now it's time to add the desired platform to the project. As usual, use Terminal on OS X or DOS Prompt on Windows to run these commands.

  1. Launch a command-line tool (DOS or Terminal) and change the directory to the directory where we just downloaded the Cordova/PhoneGap distribution, as shown here:
    $ cd hello
    
  2. In order to create a PhoneGap project for Android, all you have to do is run the command to add a platform to the project:
    $ phonegap platform add android
    

The command tells Cordova to add support for the Android platform. After the successful execution of the command, you can see a new directory named android created inside the platform directory. This contains all the platform-dependent files.

Now it's time to run the project in the emulator. The following command will take some time to complete:

$ phonegap emulate android

The tool will check whether some virtual devices are already defined and prompt the user to define one if not. If there is more than one device already defined, the tool will ask which one to use.

What just happened?

You created a PhoneGap project and emulated the app in one of the testing devices configured within your Android SDK.

Working with other platforms

To work with different platforms such as iOS, Windows Phone, and others, you have to follow the same process that we did for Android. The list of platforms that you can add to your project depends on the platform name. Before you add the platforms, you should ensure that you have the required SDKs installed on your machine.

On a Windows machine, you can run any of the following commands provided you have the required SDKs installed for each platform. You will not see the iOS platform here as we need a Mac machine to work on iOS:

C:\hello> phonegap platform add wp7
C:\hello> phonegap platform add wp8
C:\hello> phonegap platform add windows8
C:\hello> phonegap platform add amazon-fireos
C:\hello> phonegap platform add android
C:\hello> phonegap platform add blackberry10
C:\hello> phonegap platform add firefoxos

In the preceding commands, wp7 and wp8 denote Windows Phone 7 and 8, respectively.

On a Mac machine, you can develop on the following platforms after installing the corresponding platform SDKs. You will not see the Windows Phone platform here as we need the Windows operating system to install the Windows Phone SDK:

$ phonegap platform add ios
$ phonegap platform add amazon-fireos
$ phonegap platform add android
$ phonegap platform add blackberry10
$ phonegap platform add firefoxos
You have been reading a chapter from
PhoneGap Beginners Guide (third edition)
Published in: Jul 2015
Publisher:
ISBN-13: 9781784392284
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image