{"id":486,"date":"2018-03-12T04:54:04","date_gmt":"2018-03-12T04:54:04","guid":{"rendered":"http:\/\/www.creativesparksolutions.com\/blog\/?p=486"},"modified":"2018-03-12T15:33:53","modified_gmt":"2018-03-12T15:33:53","slug":"creating-your-first-phonegap-application","status":"publish","type":"post","link":"https:\/\/www.creativesparksolutions.com\/blog\/creating-your-first-phonegap-application\/","title":{"rendered":"Creating your First Phonegap application"},"content":{"rendered":"<p><strong>Assumptions:<\/strong> Usage of the command-line interface (CLI) is clear, PhoneGap has already been installed.<\/p>\n<h3>Creating a new application<\/h3>\n<p>1. Let&#8217;s create our first application called HelloWorld with:<br \/>\n<code>phonegap create HelloWorld<\/code><br \/>\nA: It should print the following response:<br \/>\n<i> Creating a new cordova project.<\/i><\/p>\n<p>2. The next step is to go into the project with:<br \/>\n<code>cd HelloWorld<\/code><br \/>\n3. If you list the content of the directory:<br \/>\n<code>ls -l<\/code><br \/>\nIt should print the following directory structure for your new PhoneGap<br \/>\nproject.<\/p>\n<p>We see four different directories and a config.xml file for setting up a<br \/>\nspecific configuration for the application in general or for a specific platform.<br \/>\nLet&#8217;s run it to see how your first application looks; later, we will explore what<br \/>\neach of the directories means and how to use them.<br \/>\n<code>phonegap run android<\/code><\/p>\n<p>Note: Don&#8217;t worry if you haven&#8217;t added Android platform support before running<br \/>\nit on Android; it does all this automatically. Here is a printout of all the<br \/>\nactions it takes:<\/p>\n<p>4. If you previously carried out the setup procedure, after a short moment you<br \/>\nshould see the following screen on the Android emulator<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.creativesparksolutions.com\/blog\/wp-content\/uploads\/2018\/03\/phonegap1.png\" alt=\"Phonegap rendered  Hello  World\" width=\"301\" height=\"515\" class=\"aligncenter size-full wp-image-488\" srcset=\"https:\/\/www.creativesparksolutions.com\/blog\/wp-content\/uploads\/2018\/03\/phonegap1.png 301w, https:\/\/www.creativesparksolutions.com\/blog\/wp-content\/uploads\/2018\/03\/phonegap1-175x300.png 175w\" sizes=\"auto, (max-width: 301px) 100vw, 301px\" \/><\/p>\n<p>If you Open the root folder of the project in your favorite text editor and open the www\/index.html file.<br \/>\nYou will HTML code with css and Javascript files called in the html.<\/p>\n<p>One of the  javascript file linked to this html controls the changes i.e index.js. There is also the cordova.js file. Every application needs to load the cordova.js file first, if you want to use PhoneGap&#8217;s plugin API; as it provides events when it is ready to use them. <\/p>\n<h3> Options when creating a new PhoneGap Project<\/h3>\n<p>What you saw above is a very simple example of how a phonegap project was created with minimum options. However there are many options and alternatives provided when creating the project in the following format: <\/p>\n<p><code>phonegap create [options] <path> [id] [name] [config]<\/code><\/p>\n<p>Let&#8217;s go over the most important parameters, as follows:<\/p>\n<p>\u2022 options: There are few available options to fine tune our new project:<br \/>\n\u00b0\u00b0 &#8211;name <name>: It specifies the application name.<br \/>\n\u00b0\u00b0 &#8211;id <package>: It specifies the package name ID. If this is missing, it defaults to com.phonegap.hello-world. It should follow a similar reverse domain name notation for the package ID.<\/p>\n<p>\u00b0\u00b0 &#8211;template <name>: By providing the name of the template, PhoneGap will create a new project from that template.<br \/>\n\u00b0\u00b0 &#8211;copy-from <path>: It will create a new project by copying the whole file structure of an existing PhoneGap application that can be modified and edited without changing the original project. This is useful if you have a boilerplate project prepared for your favorite stack of tools that you are using in the project.<br \/>\n\u00b0\u00b0 &#8211;src <path>: It does the same thing as the copy-from parameter.<br \/>\n\u00b0\u00b0 &#8211;link_to <path>: The link_to parameter links the new project to another project that already has a working code. This is useful if you want to try out new configurations or change the settings in any of the platforms without the worry that you might break something and need to rebuild it from the beginning for a specific platform.<br \/>\n\u2022 id: It is just shorthand writing for the options ID setting.<\/p>\n<p>\u2022 name: It is just shorthand writing for the options name setting.<br \/>\n\u2022 config: It provides you with the ability to pass a JSON string with additional<br \/>\nsettings that will be injected into .\/.cordova\/config.json file.<\/p>\n<h4>Here are some examples of how to use the Phonegap project creation command with Options<\/h4>\n<p>Task: To create an application with the PhoneGap Essentials name in the essentials directory and the com.phonegap-essentials package ID<\/p>\n<p><code>phonegap create essentials --name \"PhoneGap Essentials\" --id \"com.phonegap-essentials\"<\/code><\/p>\n<p>Task: To make a copy of the existing application with a new package ID named com.phonegap-advanced, you can copy the existing application in it.<br \/>\n<code>phonegap create advanced \u2014id \"com.phonegap-advanced\" \u2014copy-from .\/essentials<\/code><\/p>\n<h4> Managing Platforms when Creating a Project<\/h4>\n<p>Creating a new project is pretty much empty and it does not do a lot until you specify which platforms you would like your application to support; thus, we need to add each platform separately.  (iOS, Android, Blackberry, Symbian OS etc.)<\/p>\n<p>All the commands to manage the platform have in common the start of the command:<br \/>\n<code>phonegap platform <command><options><\/code><\/p>\n<p><strong>NOTE:<\/strong> All commands should be run in the root folder of the PhoneGap project to be able to work, except the command to create a new PhoneGap project, which can be run anywhere.<br \/>\nLet&#8217;s see a couple of examples:<br \/>\n<code>phonegap platform add ios android<\/code>  &#8211; This adds two platforms<br \/>\n<code>phonegap platform list<\/code> &#8211; Lists the platforms<\/p>\n<p>That&#8217;s it for now , for creating a new Simple Phonegap application. We&#8217;ll talk about this further  in our next tutorial which is continuation and about  BUILDING and RUNNING THE Application.<\/p>\n<p><i class=\"fa fa-hand-o-right\" aria-hidden=\"true\"><\/i>You can check out our <strong><a href=\"http:\/\/www.creativesparksolutions.com\/mobile-apps\/cross-platform-mobile-app-development-company-india.html\" rel=\"noopener\" target=\"_blank\">PhoneGap App development Services from India<\/a><\/strong> and find out more if you&#8217;re looking to get a Cross Platform app built.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content --><!-- AddThis Related Posts generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Assumptions: Usage of the command-line interface (CLI) is clear, PhoneGap has already been installed. Creating a new application 1. Let&#8217;s create our first application called HelloWorld with: phonegap create HelloWorld A: It should print the following response: Creating a new cordova project. 2. The next step is to go into the project with: cd HelloWorld 3. If you list the content of the directory: ls -l It should print the following directory structure for your new PhoneGap project. We see four different directories and a config.xml file for setting up a specific configuration for the application in general or for [&hellip;]<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><!-- AddThis Related Posts generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":495,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3],"tags":[62,63],"class_list":["post-486","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mobile-app-development","category-mobile-app-tools","tag-phonegap","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.creativesparksolutions.com\/blog\/wp-json\/wp\/v2\/posts\/486","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.creativesparksolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.creativesparksolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.creativesparksolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.creativesparksolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=486"}],"version-history":[{"count":6,"href":"https:\/\/www.creativesparksolutions.com\/blog\/wp-json\/wp\/v2\/posts\/486\/revisions"}],"predecessor-version":[{"id":493,"href":"https:\/\/www.creativesparksolutions.com\/blog\/wp-json\/wp\/v2\/posts\/486\/revisions\/493"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.creativesparksolutions.com\/blog\/wp-json\/wp\/v2\/media\/495"}],"wp:attachment":[{"href":"https:\/\/www.creativesparksolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.creativesparksolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.creativesparksolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}