Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
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 4 Mobile Application Development Cookbook

You're reading from   PhoneGap 4 Mobile Application Development Cookbook Build real-world hybrid mobile applications using the robust PhoneGap development platform

Arrow left icon
Product type Paperback
Published in Oct 2015
Publisher
ISBN-13 9781783287949
Length 356 pages
Edition 1st Edition
Arrow right icon
Toc

Table of Contents (14) Chapters Close

Preface 1. Welcome to PhoneGap 3 FREE CHAPTER 2. Movement and Location – Using the Accelerometer and Geolocation Sensors 3. Filesystems, Storage, and Local Databases 4. Working with Audio, Images, and Video 5. Working with Your Contacts List 6. Hooking into Native Events 7. Working with XUI 8. Working with the Ionic Framework 9. Ionic Framework Development 10. User Interface Development 11. Extending PhoneGap with Plugins 12. Development Tools and Testing Index

Creating a new project

Creating a new PhoneGap project is easy thanks to PhoneGap CLI. Unlike older versions of PhoneGap, where we needed to download the project template manually, we can create new projects directly from the command line. With just a single command, we can create a new project and start writing our application.

How to do it…

To create a new PhoneGap project, open your terminal or cmd. Then go to the directory where you want to maintain your source code. Run the following command:

phonegap create hello com.myapp.hello HelloWorld

It may take some time to complete the process, so be patient and let PhoneGap CLI do its magic. You will see some message during the project creation process:

How to do it…

Creating a new project progress

Congratulations! You have created your first PhoneGap project. Now, let's browse the project directory. You will see the directories as shown in the following screenshot:

How to do it…

The PhoneGap project structure

Most of the directories are empty; we will discuss the use of each directory later in the next recipe. The www/ directory is where you write code for your application. PhoneGap generated the initial starter app to work with.

How it works…

The phonegap create command is a command used to create a new project. The first argument, hello, specifies a directory for your project. Note that this directory must not exist initially; phonegap will create it for you.

The second argument, com.myapp.hello, is your application ID. The application ID is used as a unique identifier for an application. Two identical applications with different application IDs will be considered two different applications. The application ID is in reverse domain style. You can create something like com.yourdomain.applicationname.

The third argument, HelloWorld, is your application name. The application name will be used as the application's display title. This argument is optional. If you are not setting the application name, it will use the name from the first argument. If you want to change the name, you can open config.xml and edit the name element.

While we are running the phonegap create command, there are several things happening in the background:

  • The phonegap creates a new PhoneGap project with the given name and ID in the newly created directory. In our case, a PhoneGap project with the name as HelloWorld and ID as com.myapp.hello will be created under the hello directory.
  • The phonegap downloads the starter application and places it in www/ so that we can run the project directly after creating it.

    Tip

    You can use the -d option with any phonegap command to allow a verbose output. The -d option will give clear information about what is going on and the current status of the command.

You have been reading a chapter from
PhoneGap 4 Mobile Application Development Cookbook
Published in: Oct 2015
Publisher:
ISBN-13: 9781783287949
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