Slippery Rock University Dr. Deborah Whitfield Go Browns!

Phone Gap Chapter 2: Building Your First PhoneGap Project
Cross-Platform Mobile App Development
CpSc 215

(Project File) Structure


Using the CLI

Good list of commands – all of which are actually command line arguments to the phonegap command:
$ phonegap platform add android
platform add, remove, list, update
plugin search, add, remove, list
build prepare, then compile
emulate
serve
A note on notation:


Cordova Events addEventListener Create the Hello World app. (Feel free to use the desktop version of PhoneGap.) And then modify the output.

Phonegap's Javascript code

Within the head section of the html, you will always need:
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
Within the body, you will always need:
 <script type="text/javascript" src="cordova.js"></script>
You will also always need to add the event listener either directly in the body or by including a .js that does so:
<script type="text/javascript" >
        document.addEventListener('deviceready', letsGO, false);
	function letsGO() {
		// startup Code here
	}
</script>

Another way the inclusion of deviceready can be done is via the index.js code that is created for new projects using Phonegap desktop.

Open up the js folder and find index.js
Note the code that declares the object app. it contains functions initialize, bindEvents, onDeviceReady, and received Event:

var app = {
    initialize: function() {
        this.bindEvents();
    },
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicitly call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
		console.log('Received Event: ' + id);
    } 
};

Let's try some coding

Add a function to index.js called testit() that:
Debugging in a browser Building & Deployment – Much easier using PhoneGap Build. You are actually creating X-platform apps!

The Desktop version takes care of the commands. PhoneGap Build does even more… You just upload the individual (custom) assets and it does the rest.