SlideShare a Scribd company logo
1 of 137
Download to read offline
Development
Platform
-	You	can	run	it	on	almost	all	the	platforms
-	The	only	issue	is	that	to	build	for	iOS	you	need	an	OS	X
device
-	Using	online	build	services	you	still	have	dependencies	to
OS	X
Available	Tools
-	Sublime	Text
-	Vim
-	Eclipse
-	IntelliJ	IDEA
-	Adobe	Brackets
Sublime	Text
-	You	can	split	the	editor	in	columns	and	edit	multiple	files
simultaneously
-	Distraction	free	mode
-	Super	fast	search	engine
-	Super	fast	startup
-	Plugins	based	(css	prefixer,	linter,	etc.)
Vim
-	Fast
-	Diffused
-	It's	a	command	line	tool
Eclipse
-	Very	well	integrated	with	Android	(ADT)
-	Multi	language
-	Rich	of	plugins
-	Command	line	integrated	through	plugins
IntelliJ	IDEA
-	Low	memory	consumption
-	Multi	language
-	Advanced	code	completion
-	Refactoring	tools
-	Highly	integrated	with	Android	(Android	Studio)
Adobe	Brackets
-	Very	integrated	with	PhoneGap	services
-	Based	upon	standards
-	Inline	CSS	editor
-	Live	editing	in	the	browser
Install	PhoneGap
-	Download	the	distribution	you	are	targeting	
(phonegap.com	or	github)
-	Unzip	it	and	explore	the	directories
Run	the	Latest
Distribution
Update	the	.cordova/config.json	so	it	has	this	structure:
{
		lib:{
				android:{
						id:'cordova-with-no-plugins',
						version:'3.0',
						uri:'/Users/giorgionatili/phonegap/src/cordova-android'
The	Directories
|-doc/	...........	source	documentation
				|-lib/	...........	platform	code	for	supported	operating	systems
								|	|-android/
								|	|-blackberry/
								|	|-cordova-cli/
								|	|-ios/
								|	|-osx/
								|	|-windows-phone-7
								|	|-windows-phone-8
								|	|-windows8/
				|-changelog	.....	a	changelog	compiled	from	comments	and	authors
				|-license	.......	the	Apache	Software	License	v2
Node.js	(+	npm)
-		It's	a	way	of	running	JavaScript	outside	the	web	browser
-	It's	a	wrapper	around	the	high-performance	V8	JavaScript
runtime	(Chrome)
-	Useful	to	create	web	apps	or	to	execute	cli	utilities	written
in	JavaScript
-	Download	and	install	it	http://nodejs.org/
The	Required	SDKs
-	Android:	http://developer.android.com/sdk/index.html
-	BlackBerry	10:
https://developer.blackberry.com/html5/downloads/
-	Firefox	OS:	http://goo.gl/Ugyst
-	iOS
https://developer.apple.com/devcenter/ios/index.action
-	Windows	Phone	http://goo.gl/qjWro
Android	SDK	
$	export	PATH=$PATH:~/android-sdks/tools/
$	export	PATH=$PATH:~/android-sdks/platform-tools/	
(or	edit	your	.bash_profile	file)	
Create	a	virtual	device:
ā€¢ Android	4.0.3	ā€“	API	Level	15ā€³	(i.e.	Ice	Cream	Sandwich	MR1)
ā€¢ Assign	2	GiB	to	the	SD	card
ā€¢ Use	the	skin	ā€œWXGA720ā€³
ā€¢ Set	the	value	"Yes"	for	the	Hardware	Back/Home
BlackBerry	SDK
-	Add	the	tools	path	to	your	bash_profile	file				
/Developer/SDKs/Research	In	Motion/BlackBerry	10	WebWorks	SDK	1.0.4.11/dependencies/tools
-	Get	the	BlackBerry	10	application	signing	keys		and	generate	a
debug	token	
blackberry-signer	-csksetup	-cskpass	CSJ_PASS
blackberry-signer	-register	-csjpin	15111974	-cskpass	CSJ_PASS	
~/Documents/blackberrykeys/client-RDK-2031902.csj
blackberry-signer	-register	-csjpin	15111974	-cskpass	CSJ_PASS	
~/Documents/blackberrykeys/client-PBDT-2031902.csj
iOS	SDK
-	Download	and	install	the	last	version	of	Xcode
-	Install	ios-sim	(a	command-line	utility	that	launches	the
app	on	the	Simulator)
$	curl	-L	https://github.com/phonegap/ios-sim/zipball/1.3	-o	ios-sim-1.3.zip
$	unzip	ios-sim-1.3.zip
$	rake	install	prefix=/usr/local/
Windows	Phone
-	Download	and	install	Visual	Studio
-	Download	and	install	Cygwin	http://www.cygwin.com
Chrome
-	Dev	Tools
-	Remote	Debugging
-	Experimental	flags
Internet	Explorer
-	Dev	Tools
-	Workers	debugging
Firefox
-	3D	View
-	Scratchpad
Safari
-	Remote	Debugging
Make	Your	Shell
Sexy
-	Install	iTerm	(Split	pane	view,	search	highlight,	mouse-less
copy)
-	Install	zsh	(shared	command	history,	full	of	plugins,	dot
files)
-	Pickup	a	nice	theme	here
Download	the	target	SDK,	install	node.js,	npm	and	
check	that	node	is	working.	
Download	and	install	a	dev	environment.
Install	cordova-cli
$	npm	intall	cordova	-g
$	sudo	chown	-R	giorgionatili	/usr/local/lib/node_modules/cordova
Create	a	Project
$	cordova	create	MySampleProject
Add	a	Platform	+
Run!
$	cordova	platforms	add	android
$	cordova	emulate	android
Check	it	running
The	index.html	file
<html>
				<head>
								<meta	charset="utf-8"	/>
								<meta	name="format-detection"	content="telephone=no"	/>
								<meta	name="viewport"	
								content="user-scalable=no,	initial-scale=1,	maximum-scale=1,	
								minimum-scale=1,	width=device-width,	height=device-height,	target-densitydpi=device-dpi"	
/>
								<link	rel="stylesheet"	type="text/css"	href="css/index.css"	/>
								<title>Hello	World</title>
				</head>
				<body>
The	index.js	file
var	app	=	{
				//	Application	Constructor
				initialize:	function()	{
								this.bindEvents();
				},
				//	Bind	Event	Listeners
				//
				//	Bind	any	events	that	are	required	on	startup.	Common	events	are:
				//	'load',	'deviceready',	'offline',	and	'online'.
				bindEvents:	function()	{
								document.addEventListener('deviceready',	this.onDeviceReady,	false);
				},
Using	cordova-cli	create	a	new	PhoneGap	project	and	
run	it	on	a	test	device	or	emulator.
Clouds	Build
Services
-	Less	pain	configuring	all	the	target	platforms
-	GitHub	integration
-	Easy	install	process
Build	Using
cordova-cli	
$	create	path	[id	[name]]
$	cordova	platform	add	[platform]|rm|ls
$	cordova	prepare	[platform]
$	cordova	compile	[platforms]
$	cordova	build
$	cordova	emulate	[platforms]
The	Project	Folders
myApp/
|--.cordova/
|--	merges/
|	|--	android/
|	|--	blackberry/
|	`--	ios/
|--	platforms/
|	|--	android/
|	|--	blackberry/
|	`--	ios/
|--	plugins/
`--	www/
The	config.xml	file
(a	detailed	explanation	of	the	allowed	tags	is	available
here	http://goo.gl/GqXY0)
<widget	xmlns					=	"http://www.w3.org/ns/widgets"
								xmlns:gap	=	"http://phonegap.com/ns/1.0"
								id								=	"com.phonegap.hello-world"
								version			=	"1.0.0">
				<name>Hello	World</name>
				<description>
								Hello	World	sample	application	that	responds	to	the	deviceready	event.
The	Browser
-	Find	the	relevant	code	in	the	debuggerā€™s	code	view	pane
-	Set	breakpoint(s)	where	you	think	interesting	things	may
occur
-	Run	the	script	again	by	reloading	the	page	in	the	browser
-	Investigate	the	values	of	variables
iWebInspector	(OS	X
only)
-	A	tool	to	debug,	profile	and	inspect	web	applications
running	on	iOS	Simulator
-	It	works	on	iOS	5	and	iOS	5.1
-	Find	the	application:didFinishLaunchingWithOptions
method	in	the		AppDelegate.m	file	and	add	the	following
snippet
iOS	6	Remote
Debugging
-	You	must	have	the	Safari	Develop	Menu	enabled
-	Open	Develop	->	(iPad	||	iPhone)	Simulator	and	click	the
active	session
Debug	with	weinre
(WEb	INspector
REmote)
-	Install	weinre	using	the	command	line	tool
$	npm	install	weinre	-g
-	Add	the	script	tag	needed	to	load	the	required	libraries
<script	src="http://xxx.xxx.xxx.xxx:8080/target/target-script.js#anonymous"></script>
-	Run	it	from	your	command	line	and	open	a	browser
weinre	-boundHost	xxx.xx.xx.x
Configure	your	app	in	order	to	run	a	remote	debug	
session	using	weinre
Ripple
-	Apache	Rippleā„¢	is	a	web	based	mobile	environment
simulator	designed	to	enable	rapid	development	of	mobile
web	applications	
-	It	works	via	a	Chrome	extension,	which	means,	obviously,
it	is	Chrome	only
-	It	supports	most	of	the	platforms	supported	by	PhoneGap
$	cordova	ripple	[platform]
The	Ripple	UI
Responsive
Inspector
-	Allows	viewing	defined	media	queries	of	HTML	pages
-	Useful	when	developing	responsive	web	layouts	
-	Available	as	a	Chrome	extension
Responsive
Inspector	UI
Live	Reload
-	It's	a	utility	that	refreshes	the	page	for	you	each	time	it
detects	a	change	to	a	file	in	a	directory
-	You	can	activate	it	using	an	extension
http://goo.gl/kZaCl	or	by	adding	the	following	script	to	the
page
<script>document.write('<script	src="http://'	+	(location.host	||	'localhost').split(':')[0]	+	':35729/livereloa
Emulator	vs	Device
-	Emulators	allow	you	to	make	a	first	check	and	fix	the	most
obvious	bugs
-	Emulators	offer	a	(relatively)	easy	way	to	run	apps	on
multiple	platforms
-	Devices	allow	to	run	real	tests
-	Devices	fragmentation	don't	allow	you	to	run	tests	on	all
the	devices
-	Bugsense	and	crowdtesting	can	help	developers	to	deploy
reliable	apps
Cordova	CLI
-	You	can	run	the	main	commands	from	any	folder
-	When	working	on	a	specific	target	platform	run	the
commands	contained	in	the	cordova	folder	
-	Keep	devices	connected	to	your	dev	environment	in	order
to	test	often
PhoneGap
Architecture
PhoneGap	Event
Flow
Performance	Tips
-	Avoid	embed	and	inline	scripts
-	Minimize	repaints	and	reflows
-	Minimize	HTML	files
-	Compress	and	combine	JavaScript	and	CSS	files
-	Use	CSS	sprites
Compressions	Tools
-	There	are	several	compression	tools	(YUI	Compressor,
JSMin,	Closure,	KJScompress,	bananascript)
-	UglifyJS2	started	to	be	pretty	famous	since	jQuery	started
to	use	it
-	Very	simple	to	install	and	to	use
$	npm	install	uglify-js	-g
$	cat	file1.js	file2.js	|	uglifyjs	--inline-script	-o	mytest.min.js
Client	Side
Templating
A	document	that	contains	parameters,	identified	by	some	special
syntax,	that	are	replaced	by	actual	arguments	by	the	template
processing	system
-	It	is	a	great	way	to	separate	markup	and	logic	in	views
-	It's	due	to	shift	of	the	app	logic	from	server	to	client
Templating	Engines
-	underscore.js,	templates	are	fast	and	lightweight	
-	ICanHaz.js,	returns	jQuery	object
-	Google	Closure	Templates,	robust	and	reliable
-	Mustache.js,	no	logic	in	the	templates	that	are	language
agnostic
-	Even	more...
Template	and	Data
A	template	and	its	data	look	like	the	following	snippets:
<h1>{{title}}</h1>
<ul>
				{{#names}}
								<li>{{name}}</li>
				{{/names}}
</ul>
var	data	=	{
				"title":	"Story",
				"names":	[
								{"name":	"Tarzan"},
Using	Templates
-	A	template	can	be	loaded	on	runtime	or	compiled	and
stored	in	a	variable
-	A	useful	tool	to	compile	the	template	as	a	variable	is
pistachio	
$	npm	install	pistachio	-g
$	pistachio	--out=splash-tpl.js	splash-tpl.html
JavaScript	AMD
Specifies	a	mechanism	for	defining	modules	such	that	the	module	and
its	dependencies	can	be	asynchronously	loaded
-	Well	suited	for	the	browser	where	synchronous	loading	incurs
performance,	usability,	debugging,	and	cross-domain	access
problems
ā€¢ Dojo:	dojo.require('some.module')
ā€¢ LABjs:	$LAB.script("some/module.js')
ā€¢ CommonJS:	require('some/module').
Require.js
-	JavaScript	file	and	module	loader
-	Optimized	for	in-browser	use,	but	it	can	be	used	in	other	JS
environments	
<script	data-main="js/app"	src="js/libs/require/require.js"></script>
www/
|--	js/
|	|--	app.js
|	|--	main.js
|	|--	libs/
Anatomy	of	a
Module	1/2
-	Each	module	is	defined	in	a	separate	JavaScript	file
-	A	module	is	defined	using	the	define	keyword	and	return
something
define({
				color:	"black",
				size:	"unisize"
Anatomy	of	a
Module	2/2
-	Some	define()	calls	that	include	a	name	for	the	module	as
the	first	argument
-	If	the	module	has	dependencies,	the	first	argument	should
be	an	array	of	dependency	names,	and	the	second
argument	should	be	a	definition	function
Using	the	require.js	syntax	create	a	new	PhoneGap
application	that	reacts	to	the	deviceready	event.
Local	Storage
-	The	Local	Storage	API	is	part	of	the	Web	Storage	API	defined	by	the
W3C	in	order	to	provide	a	guideline	for	persistent	data	storage	of	key-
value	pair	data	in	web	clients
-	Local	Storage	API	is		designed	to	support	data	that	needs	to	be
available	between	sessions
The	localStorage
Object
It	exposes	several	properties	and	methods:
ā€¢ key:	returns	the	name	of	the	key	stored	at	a	specific	position
ā€¢ getItem:	returns	the	item	identified	by	a	key
ā€¢ setItem:	saves	some	data	in	a	specific	key	(i.e.	a	string)	of	the
localStorage	object
The	StorageEvent
Object
Each	time	the	localStorage	object	is	updated	a	StorageEvent	is	fired.
This	event	cannot	be	cancelled	and	contains	the	following	properties:
ā€¢ key:	a	string	that	represents	the	named	key	that	was	added,
removed,	or	modified
ā€¢ oldValue:	the	previous	value	of	the	named	key	if	it	was	updated
or	null
LocalStorage
Drawbacks
-	The	API	is	synchronous	and	for	this	reason	the	app	appears	less
responsive	because	the	time	needed	to	access	the	localStorage
object	is	greater	than	the	one	needed	to	access	an	object	in	memory
-	Complex	data	needs	to	be	serialized	and	de-serialized	impacting	the
responsiveness	of	the	app
Create	a	sample	app	able	to	store	in	the	local	storage	previously	
typed	words	so	that	the	end	user	can	easily	
get	some	suggestions	the	next	time	is	using	the	app
SQL	Storage
-	PhoneGap	provides	SQL	storage	API	based	on	the	Web	SQL
specification
-	When	a	device	already	offers	support	for	Web	SQL	the	app
will	use	it	otherwise	the	app	will	use	the	PhoneGap	one
-	As	a	developer	you	will	not	notice	any	difference,	because
you	will	not	have	to	change	any	line	of	code
Create	the	App
Database
In	order	to	start	to	work	with	a	Database	object	itā€™s	enough	to	store
in	a	variable	whatā€™s	returned	by	the	openDatabase	method
var	size	=	(1024	*	1024	*	2);	
var	db	=	window.openDatabase("test",	"1.0",	"Test	DB",	size);
The	openDatabase	method	accepts	four	arguments;	the	name	of	the
The	DataBase
Object
The	DataBase	object	returned	by	the	openDatabase	method	exposes
two	methods:
ā€¢ transaction	->	execute	an	SQL	transaction
ā€¢ changeVersion	->	changes	the	version	of	the	db	(useful	when
updating	a	schema)
The	SQLTransaction
Object
The	object	is	returned	as	an	argument	in	the	function	defined	as	first
argument	of	the	transaction	method
The	executeSql	method	allows	executing	SQL	queries:
function	createTables(transactionObj){
Arguments	and	the
Query
You	can	use	place	holders	to	pass	arguments	to	a	query	when	using
the	transaction	method
function	addData(name,	surname,	gender){		
				db.transaction(function(transactionObj){
								var	sql	=	'INSERT	INTO	users	(name,	surname,	gender)	VALUES	(?,	?,	?);';
The	SQLResultSet
Object
When	a	SQLTransaction	object's	executeSql	method	is	called,	the
specified	callback	executes	with	a	SQLResultSet	parameter
containing	three	properties:
ā€¢ The	insertId	returns	the	row	number	of	a	successfully	SQL
insertion	statement
The	SQLResultSetRow
The	SQLResultSetRowList	contains	the	data	returned	from	a	SQL
select	statement,	the	object	exposes:
function	querySuccess(tx,	results)	{
				var	len	=	results.rows.length;
								
								for	(var	i=0;	i<len;	i++){
ā€¢ The	length	property	indicating	how	many	rows	the	select
statement	returns
ā€¢ The	item	method	to	recover	data	at	a	specific	index
DataBase
Limitations
Limitations	are	not	related	to	PhoneGap	itself	but	are	due	to	the	Web
View	implementation	of	each	target	platform
ā€¢ The	size	limit	varies	accordingly	to	the	OS	from	5	to	25	Mb
ā€¢ Since	iOS	5.x	databases	have	been	moved	to	the	folder
~/Library/Caches	from	~/Library/WebKit
Create	a	sample	app	able	to	store	and	read	some	data	
from	a	local	database
Accelerometer
The	accelerometer	is	actually	made	up	of	three	accelerometers	and
each	one	measures	the	changes	in	velocity	(i.e.,	linear	acceleration)
over	time	along	the	linear	path	on	the	axis	x,	y,	and	z
Accelerometer
Object
The	accelerometer	detects	the	values	of	the	delta	movement	relative
to	the	current	device	position
You	can	detect	the	device	acceleration	data	using	the	method
getCurrentAcceleration	or	setting	up	a	watcher	through	the	method
watchAcceleration
In	order	to	stop	watching	the	accelerometer	data	itā€™s	enough	to	call
Accelerometer	Data
var	options	=	{maximumAge:	3000,	timeout:	5000,	enableHighAccuracy:	true	};
navigator.geolocation.watchPosition(onScucces,	onFailure,	options);
function	onSuccess(position)	{
				console.log('Coordinates:	'	+	position.coords);
				console.log('Altitude:	'	+	position.coords.altitude);
				console.log('Altitude:	'	+	position.coords.altitude);
	console.log('Accuracy:	'	+	position.coords.accuracy);
	console.log('Altitude	Accuracy:	'	+	position.coords.altitudeAccuracy);
	console.log('Heading:	'	+	position.coords.heading);
	console.log('Speed:	'	+	position.coords.speed);
Create	a	sample	app	to	detect	device	shakes	using	a	
numeric	value	as	bound	between	the	previous	and	actual	
position	of	the	device
Compass
The	PhoneGap	Compass	API	allows	you	to	obtain	the	direction	that
the	device	is	pointing	to
The	Compass	API	is	available	on	the	compass	property	of	the
navigator	object	and	exposes	the	following	methods:
ā€¢ compass.getCurrentHeading,	reads	the	current	compass
heading	through	a	handler
ā€¢ compass.watchHeading,	reads	the	compass	heading	at	a
specific	time	interval	through	an	handler	and	return	a	reference	to
it
CompassHeading
Object
It's	returned	as	an	argument	in	the	success	handler	of	the
watchHeading	and	getCurrentHeading	methods,	the	object	exposes
the	following	properties:			
ā€¢ magneticHeading,	the	heading	in	degrees	from	0	to	359.99
ā€¢ trueHeading,	the	heading	relative	to	the	geographic	North	Pole
CompassError
Object
The	CompassError	object	has	a	property	named	code	that	returns
two	possible	values	CompassError.COMPASS_INTERNAL_ERR	or
CompassError.COMPASS_NOT_SUPPORTED
function	onCompassError(error){
								switch(true){
Consider	the	following	snippet	of	code,	which	will	give	you	the	right
rotation	for	the	compass,	and	create	a	sample	app	showing	a
Geolocation
The	term	geolocation	is	used	in	order	to	refer	to	the	identification
process	of	the	real-world	geographic	location	of	an	object
The	location	of	a	device	is	represented	through	a	point,	the	point	is
comprised	of	two	components:	latitude	and	longitude
Geolocation	API
The	Geolocation	API	is	exposed	through	the	geolocation	object	child
of	the	navigator	object	and	consists	of	three	methods:
ā€¢ getCurrentPosition(),	returns	the	device	position
ā€¢ watchPosition(),	watches	for	changes	of	the	device	position
ā€¢ clearWatch(),	stops	the	watcher	for	deviceā€™s	position	changes
Position	Object
Accessing	its	properties	you	can	read	the	deviceā€™s	coordinates	and
the	creation	timestamp	of	the	object	that	stores	the	coordinates
function	onSuccess(position)	{
				console.log('Coordinates:	'	+	position.coords);
				console.log('Timestamp:	'	+	position.timestamp);
}
PositionError	Object
It	contains	two	properties	the	code	and	the	message	one.
function	onError(error)	{			
				switch(true){
	
		case	error.code	==	PositionError.PERMISSION_DENIED:
		//	The	user	denies	the	app	to	use	the	deviceā€™s	current	position
		break;
		case	error.code	==	PositionError.POSITION_UNAVAILABLE:
		//	The	position	of	the	device	cannot	be	determined
		break;
Camera	&	Capture	
The	main	difference	between	these	APIs	is	that	the	Camera	API	can
access	only	the	default	device	camera	application	whereas	the
Capture	API	can	also	record	audio	or	video	
Capture	API	allows	multiple	captures	with	a	single	API	call
The	Capture	API	is	an	implementation	of	an	abandoned	W3C
standards	draft
Accessing	the	Camera
The	Camera	API	exposes	two	methods	defined	in	the
navigator.camera	object:
ā€¢ getPicture,	which	opens	the	default	camera	application	or	lets
the	user	browse	the	media	library	depending	on	the	options
specified	in	the	configuration	object	the	method	accepts	as
argument	
ā€¢ cleanup,	which	cleans	up	the	image	file	stored	into	the
temporary	storage	location
Camera	Options
ā€¢ quality,	a	number	between	0	and	100	used	to	specify	the	quality
of	the	saved	image
ā€¢ destinationType,	a	number	used	to	define	the	format	of	the
value	returned	in	the	success	handler
(Camera.DestinationType.DATA_URL,	Camera.DestinationType.FILE_U
,	Camera.DestinationType.NATIVE_URI)
ā€¢ sourceType,	a	number	used	to	specify	where	the	getPicture
method	will	get	an	image
(Camera.PictureSourceType.PHOTOLIBRARY,
Camera.PictureSourceType.CAMERA,
Capturing	an	Image
var	cameraOptions	=	{targetWidth:	300,	targetHeight:	400,
																					saveToPhotoAlbum:	true,	allowEdit:	true};
navigator.camera.getPicture(onCameraSuccess,	onCameraError,	cameraOptions);
								
function	onCameraSuccess(imageData){
				//	Use	the	image	data
}
function	onCameraError(error){
Capture	API
The	Capture	API	works	asynchronously	as	most	of	the	PhoneGap	APIs
and	provides	access	to	the	audio,	image,	and	video	capture
capabilities	of	the	device
var	capture	=	navigator.device.capture;
capture.captureImage(function(files){
ā€¢ captureVideo
ā€¢ captureAudio
ā€¢ captureImage
MediaFile	Object
The	MediaFile	object	stored	in	the	files	array	returned	in	the	success
handler	describes	the	captured	media
ā€¢ fullPath,	a	string	representing	the	file	path	on	the	device
including	the	file	name
ā€¢ lastModifiedDate,	modification	date	of	the	file	expressed	in	ms
since	January	1,	1970	
ā€¢ name,	a	string	representing	the	name	of	the	file
ā€¢ size,	a	number	representing	the	size	of	the	file	in	bytes
Capture	Options
ā€¢ CaptureVideoOptions	(limit	and	duration)
ā€¢ CaptureImageOptions	(limit)
ā€¢ CaptureAudioOptions	(limit	and	duration)
CaptureError	Object
ā€¢ CaptureError.CAPTURE_INTERNAL_ERR	
ā€¢ CaptureError.CAPTURE_APPLICATION_BUSY	
ā€¢ CaptureError.CAPTURE_INVALID_ARGUMENT	
ā€¢ CaptureError.CAPTURE_NO_MEDIA_FILES	
ā€¢ CaptureError.CAPTURE_NOT_SUPPORTED
Create	a	sample	app	able	to	capture	an	image	and	
apply	the	grayscale	effect	you	can	find	here
http://www.html5rocks.com/en/tutorials/canvas/imagefilters/.
Understanding	the
API
The	PhoneGap	Files	API	is	an	implementation	of	two	different	W3C
APIs,	the	Directories	and	System	API	and	the	File	API
The	PhoneGap	Files	API	is	not	a	complete	implementation	of	the	W3C
specification,	the	missing	piece	is	the	synchronous	file	system
interface	implementation
Accessing	the	File
System
In	order	to	access	the	device	file	system	you	can	use	the
requestFileSystem	method	of	the	LocalFileSystem	object									
The	method	accepts	four	arguments:
ā€¢ The	type	of	storage	(temporary	or	persistent)
ā€¢ The	amount	of	space	in	bytes	to	be	allocated	on	the	device
Storage	Types
The	device	hard	disk	is	not	completely	open	to	the	appā€™s	view.	A	limited
portion	of	the	hard	disk	is	dedicated	to	a	single	app	alone;	this	is	the
app	sandbox.	
ā€¢ LocalFileSystem.PERSISTENT	indicates	that	the	storage	cannot
be	removed	by	the	user	agent	without	the	appā€™s	or	userā€™s
permission
ā€¢ LocalFileSystem.TEMPORARY	indicates	that	the	files	stored	in
the	requested	space	can	be	deleted	by	the	user	agent	or	by	the
system	without	the	appā€™s	or	userā€™s	permission
Reading	Directories
&	Files
function	onSuccess(fileSystem){
				var	currentRoot	=	fileSystem.root;
				var	directoryReader	=	currentRoot.createReader();
				directoryReader.readEntries(onDirSuccess,	onFileSysError);
}
FileError	Object	
ā€¢ FileError.NOT_FOUND_ERR	(returned	value	1)
ā€¢ FileError.SECURITY_ERR	(returned	value	2)
ā€¢ FileError.ABORT_ERR	(returned	value	3)
ā€¢ FileError.NOT_READABLE_ERR	(returned	value	4)
ā€¢ FileError.ENCODING_ERR	(returned	value	5)
ā€¢ FileError.NO_MODIFICATION_ALLOWED_ERR	(returned	value	6)
ā€¢ FileError.INVALID_STATE_ERR	(returned	value	7)
Writing	Data
To	write	data	to	a	file	it	suffices	that	the	app	gets	access	to	the	file
using	the	FileWriter	object
To	get	a	FileWriter	object	you	first	have	to	get	access	to	a
DirectoryEntry	or	to	a	FileEntry	object	using	the	requestFileSystem
method
Once	you	successfully	get	access	to	the	file	system	you	can	request	a
file	specifying	that	you	want	to	create	it	using	the	create	flag
function	onFileSystemSuccess(fileSystem){
Creating	a	Writer
In	the	success	handler	it's	possible	to	create	a	writer,	the
createWriter	method	also	requires	the	success	and	failure	handlers	
function	onGetFile(file){
				file.createWriter(onGetWriter,	onGetWriterError);
}
function	onGetWriter(writer){
				writer.write('Hello	PhoneGap	Files	API!');
Events
During	the	write	operation	several	events	occur;	for	each	event	there
is	a	corresponding	property	defined	on	the	FileWriter	object:
ā€¢ onwritestart	is	called	when	the	FileWriter	object	starts	to	write
the	file
ā€¢ onwrite	is	called	when	the	FileWriter	object	has	completed
successfully	the	write	operation
ā€¢ onabort	is	called	when	the	write	operation	has	been	interrupted
Reading	Data
Once	you	have	access	to	the	file	you	can	create	a	FileReader	object
and	use	its	methods:
ā€¢ readAsDataURL,	reads	file	and	return	data	as	a	base64-encoded
data	URL
ā€¢ readAsText,	reads	text	file
ā€¢ readAsBinaryString,	reads	file	as	binary	and	returns	a	binary
string
ā€¢ readAsArrayBuffer,	reads	file	as	an	ArrayBuffer
Download	and
Upload
Once	you	get	access	to	the	file	system	create	a	new	FileTransfer
object	and	call	the	download	method	specifying	the	remote	URL,	the
system	file	path	URI,	and	the		success	failure	handlers
var	ft	=	new	FileTransfer();
ft.upload(fileURI,	encodeURI("http://some.server.com/upload.php"),	onSuccess,	onError,	
options);
FileUpload	Options
ā€¢ fileKey:	the	name	of	the	form	element.	Defaults	to	file
ā€¢ fileName:	the	file	name	to	use	when	saving	the	file	on	the
server.
ā€¢ mimeType:	the	mime	type	of	the	data	to	upload
ā€¢ params:	a	set	of	optional	key/value	pairs	to	pass	in	the	HTTP
request
ā€¢ chunkedMode:	whether	to	upload	the	data	in	chunked	streaming
mode
Create	a	sample	app	and	render	a	progress	bar	
indicating	the	amount	of	file	downloaded	from	a	remote	server
Contact	Name
Object	
ā€¢ formatted,	represents	the	complete	name	of	the	contact
ā€¢ familyName,	represents	the	contactā€™s	family	name
ā€¢ givenName,	represents	the	contactā€™s	given	name			
ā€¢ middleName,	represents	the	contactā€™s	middle	name
ā€¢ honorificPrefix,	represents	the	contactā€™s	prefix	(e.g.,	Mr.	or	Dr.)
Contact	Field	Object
ā€¢ type,	a	string	that	represents	the	type	of	field,	possible	values
are	home,	work,	mobile,	and	so	on
ā€¢ value,	a	string	representing	the	value	of	the	field	such	as	a
phone	number	or	email	address
ā€¢ pref,	a	Boolean	value	that	indicates	if	in	a	specific	field	is
returned	the	user	preferred	value
Contact	Address
Object	
ā€¢ pref,	a	Boolean	that	indicates	whether	the	returned
ContactAddress	is	the	preferred	value	of	the	user	for	the
ContactAddress	object
ā€¢ type,	a	string	that	indicates	what	type	of	address	is	stored	in
the	ContactAdress	object	(e.g.,	home,	office,	etc.)
ā€¢ formatted,	a	string	that	represents	the	complete	address
Read	a	Contact
Object	
Create	a	contact:
var	contact	=	navigator.contacts.create({'displayName':	'Giorgio'});
contact.save(onContactSaved,onContactSavedError);
contact.remove(onContactRemoved,	onContactRemovedError);
Find	a	contact:
var	options	=	new	ContactFindOptions();
What	is	a	Plugin
It's	a	native	code	exposed	to	the	app	using	JavaScript	
The	native	part	extends	or	implements	platform	specific	classes	or
interfaces	(e.g.	CordovaPlugin,	CDVPlugin,	etc.)	
A	plugin	can	be	installed	and	uninstalled	using	cordova-cli	or
plugman	sadas
PhoneGap
Architecture
Plugman
Plugman	is	an	open	source	command	line	utility	distributed	as	an
npm	module	to	facilitate	the	installation	and	uninstallation	of	plugins
It	supports	the	Android,	BlackBerry	10	and	iOS	platforms	
Once	installed	you	can	use	several	commands	from	your	command
line	tool
Plugman
Commands
$	plugman	--fetch
$	plugman	--platform	android	--project	PLATFORM_PROJECT_PATH	--plugin
$	plugman	--prepare								
$	plugman	--platform	android	uninstall	--project	PLATFORM_PROJECT_PATH	--plugin
Building	Blocks	of	a
Plugin
A	PhoneGap	plugin	is	a	bridge	between	the	WebView	and	the	native
platform	the	app	is	running	on
The	only	mandatory	implementation	is	the	way	to	communicate
between	JavaScript	and	the	native	environment	using	the
cordova.exec	function
Links	
ā€¢ Official	documentation	http://docs.phonegap.com
ā€¢ Google
Group	https://groups.google.com/forum/#!forum/phonegap
ā€¢ Andrew	Trice	blob	http://www.tricedesigns.com/tag/phonegap
ā€¢ Simon	McDonald
blog	http://simonmacdonald.blogspot.com/search/label/phonegap
ā€¢ Joe	Bowser	blog	http://www.infil00p.org
ā€¢ Raymond	Camden
blog	http://www.raymondcamden.com/index.cfm/Mobile
Book(s)
Develop, test and debug cross platforms apps with PhoneGap

More Related Content

What's hot

Dd13.2013.milano.open ntf
Dd13.2013.milano.open ntfDd13.2013.milano.open ntf
Dd13.2013.milano.open ntf
Ulrich Krause
Ā 
UKLUG 2012 - XPages, Beyond the basics
UKLUG 2012 - XPages, Beyond the basicsUKLUG 2012 - XPages, Beyond the basics
UKLUG 2012 - XPages, Beyond the basics
Ulrich Krause
Ā 

What's hot (18)

A Brief Intro to Adobe Flex
A Brief Intro to Adobe FlexA Brief Intro to Adobe Flex
A Brief Intro to Adobe Flex
Ā 
WebAssembly and .NET
WebAssembly and .NETWebAssembly and .NET
WebAssembly and .NET
Ā 
PHP konferencija - Microsoft
PHP konferencija - MicrosoftPHP konferencija - Microsoft
PHP konferencija - Microsoft
Ā 
Better Drupal Interaction Design with Flex
Better Drupal Interaction Design with FlexBetter Drupal Interaction Design with Flex
Better Drupal Interaction Design with Flex
Ā 
Adobe AIR. NativeProcess. FFMPEG. Awesome.
Adobe AIR. NativeProcess. FFMPEG. Awesome.Adobe AIR. NativeProcess. FFMPEG. Awesome.
Adobe AIR. NativeProcess. FFMPEG. Awesome.
Ā 
CUST-10 Customizing the Upload File(s) dialog in Alfresco Share
CUST-10 Customizing the Upload File(s) dialog in Alfresco ShareCUST-10 Customizing the Upload File(s) dialog in Alfresco Share
CUST-10 Customizing the Upload File(s) dialog in Alfresco Share
Ā 
Php Performance On Windows
Php Performance On WindowsPhp Performance On Windows
Php Performance On Windows
Ā 
Adobe flex an overview
Adobe flex  an overviewAdobe flex  an overview
Adobe flex an overview
Ā 
PHP and FastCGI Performance Optimizations
PHP and FastCGI Performance OptimizationsPHP and FastCGI Performance Optimizations
PHP and FastCGI Performance Optimizations
Ā 
Dd13.2013.milano.open ntf
Dd13.2013.milano.open ntfDd13.2013.milano.open ntf
Dd13.2013.milano.open ntf
Ā 
Java begin so we win
Java begin so we winJava begin so we win
Java begin so we win
Ā 
Asp net
Asp netAsp net
Asp net
Ā 
Web services on IBM i with PHP and Zend Framework
Web services on IBM i with PHP and Zend FrameworkWeb services on IBM i with PHP and Zend Framework
Web services on IBM i with PHP and Zend Framework
Ā 
UKLUG 2012 - XPages, Beyond the basics
UKLUG 2012 - XPages, Beyond the basicsUKLUG 2012 - XPages, Beyond the basics
UKLUG 2012 - XPages, Beyond the basics
Ā 
Java
JavaJava
Java
Ā 
Winbatch
WinbatchWinbatch
Winbatch
Ā 
Flex 4 Overview
Flex 4 OverviewFlex 4 Overview
Flex 4 Overview
Ā 
Introduction To NetBeans IDE
Introduction To NetBeans IDEIntroduction To NetBeans IDE
Introduction To NetBeans IDE
Ā 

Similar to Develop, test and debug cross platforms apps with PhoneGap

AdobeĀ® Flexā„¢
AdobeĀ® Flexā„¢AdobeĀ® Flexā„¢
AdobeĀ® Flexā„¢
Uday Shankar
Ā 
What is Adobe Flex ?
What is Adobe Flex  ?What is Adobe Flex  ?
What is Adobe Flex ?
Antonio Correia
Ā 
An overview of mobile html + java script frameworks
An overview of mobile html + java script frameworksAn overview of mobile html + java script frameworks
An overview of mobile html + java script frameworks
Sasha dos Santos
Ā 
Cross-Platform Development using Angulr JS in Visual Studio
Cross-Platform Development using Angulr JS in Visual StudioCross-Platform Development using Angulr JS in Visual Studio
Cross-Platform Development using Angulr JS in Visual Studio
Mizanur Sarker
Ā 

Similar to Develop, test and debug cross platforms apps with PhoneGap (20)

[2015/2016] Apache Cordova
[2015/2016] Apache Cordova[2015/2016] Apache Cordova
[2015/2016] Apache Cordova
Ā 
Making a Headless Android Device (Oslo Embedded Meetup 2018)
Making a Headless Android Device (Oslo Embedded Meetup 2018)Making a Headless Android Device (Oslo Embedded Meetup 2018)
Making a Headless Android Device (Oslo Embedded Meetup 2018)
Ā 
Build Your First iPhone or Android App with Telerik AppBuilder
Build Your First iPhone or Android App with Telerik AppBuilderBuild Your First iPhone or Android App with Telerik AppBuilder
Build Your First iPhone or Android App with Telerik AppBuilder
Ā 
Making a Headless Android Device
Making a Headless Android DeviceMaking a Headless Android Device
Making a Headless Android Device
Ā 
World of Node.JS
World of Node.JSWorld of Node.JS
World of Node.JS
Ā 
Developing Windows 10 Hosted Web Apps
Developing Windows 10 Hosted Web AppsDeveloping Windows 10 Hosted Web Apps
Developing Windows 10 Hosted Web Apps
Ā 
Delphi Prism for iPhone/iPad and Linux with Mono and Monotouch
Delphi Prism for iPhone/iPad and Linux with Mono and MonotouchDelphi Prism for iPhone/iPad and Linux with Mono and Monotouch
Delphi Prism for iPhone/iPad and Linux with Mono and Monotouch
Ā 
AdobeĀ® Flexā„¢
AdobeĀ® Flexā„¢AdobeĀ® Flexā„¢
AdobeĀ® Flexā„¢
Ā 
What is Adobe Flex ?
What is Adobe Flex  ?What is Adobe Flex  ?
What is Adobe Flex ?
Ā 
Nativescript
NativescriptNativescript
Nativescript
Ā 
Droidcon uk2012 androvm
Droidcon uk2012 androvmDroidcon uk2012 androvm
Droidcon uk2012 androvm
Ā 
Pottnet Meetup Essen - ASP.Net Core
Pottnet Meetup Essen - ASP.Net CorePottnet Meetup Essen - ASP.Net Core
Pottnet Meetup Essen - ASP.Net Core
Ā 
Pottnet MeetUp Essen - ASP.Net Core
Pottnet MeetUp Essen - ASP.Net CorePottnet MeetUp Essen - ASP.Net Core
Pottnet MeetUp Essen - ASP.Net Core
Ā 
Php verses .net
Php verses .netPhp verses .net
Php verses .net
Ā 
DotNet Cologne 2015 - Windows 10 AppDev, Teil1: App Developer Basics- (Daniel...
DotNet Cologne 2015 - Windows 10 AppDev, Teil1: App Developer Basics- (Daniel...DotNet Cologne 2015 - Windows 10 AppDev, Teil1: App Developer Basics- (Daniel...
DotNet Cologne 2015 - Windows 10 AppDev, Teil1: App Developer Basics- (Daniel...
Ā 
An overview of mobile html + java script frameworks
An overview of mobile html + java script frameworksAn overview of mobile html + java script frameworks
An overview of mobile html + java script frameworks
Ā 
presentation on Android
presentation on Android presentation on Android
presentation on Android
Ā 
Ide
IdeIde
Ide
Ā 
Cross-Platform Development using Angulr JS in Visual Studio
Cross-Platform Development using Angulr JS in Visual StudioCross-Platform Development using Angulr JS in Visual Studio
Cross-Platform Development using Angulr JS in Visual Studio
Ā 
Windows 10 pentru dezvoltatori - InfoEducație 2015
Windows 10 pentru dezvoltatori - InfoEducație 2015Windows 10 pentru dezvoltatori - InfoEducație 2015
Windows 10 pentru dezvoltatori - InfoEducație 2015
Ā 

More from Giorgio Natili

I beacon mobile_tea
I beacon mobile_teaI beacon mobile_tea
I beacon mobile_tea
Giorgio Natili
Ā 
The short path to ecma 6
The short path to ecma 6The short path to ecma 6
The short path to ecma 6
Giorgio Natili
Ā 
Mobile raspberry pi
Mobile raspberry piMobile raspberry pi
Mobile raspberry pi
Giorgio Natili
Ā 
WebRTC communication and wearable devices
WebRTC communication and wearable devicesWebRTC communication and wearable devices
WebRTC communication and wearable devices
Giorgio Natili
Ā 
Multithreading development with workers
Multithreading development with workersMultithreading development with workers
Multithreading development with workers
Giorgio Natili
Ā 
Ecma6 in 30 minutes
Ecma6 in 30 minutesEcma6 in 30 minutes
Ecma6 in 30 minutes
Giorgio Natili
Ā 
TDD and PhoneGap
TDD and PhoneGapTDD and PhoneGap
TDD and PhoneGap
Giorgio Natili
Ā 
Undoable architectures
Undoable architecturesUndoable architectures
Undoable architectures
Giorgio Natili
Ā 
WebRTC and Mobile Integration
WebRTC and Mobile IntegrationWebRTC and Mobile Integration
WebRTC and Mobile Integration
Giorgio Natili
Ā 

More from Giorgio Natili (20)

Driving Assistant Solutions with Android
Driving Assistant Solutions with AndroidDriving Assistant Solutions with Android
Driving Assistant Solutions with Android
Ā 
Isomorphic Reactive Programming
Isomorphic Reactive ProgrammingIsomorphic Reactive Programming
Isomorphic Reactive Programming
Ā 
Service worker API
Service worker APIService worker API
Service worker API
Ā 
The Little Shop of TDD Horrors
The Little Shop of TDD HorrorsThe Little Shop of TDD Horrors
The Little Shop of TDD Horrors
Ā 
I beacon mobile_tea
I beacon mobile_teaI beacon mobile_tea
I beacon mobile_tea
Ā 
Android, getting started
Android, getting startedAndroid, getting started
Android, getting started
Ā 
Clear the UIViewController Mess
Clear the UIViewController MessClear the UIViewController Mess
Clear the UIViewController Mess
Ā 
Big data and mobile
Big data and mobileBig data and mobile
Big data and mobile
Ā 
The short path to ecma 6
The short path to ecma 6The short path to ecma 6
The short path to ecma 6
Ā 
Jasmine 2.0
Jasmine 2.0Jasmine 2.0
Jasmine 2.0
Ā 
Harmonik
HarmonikHarmonik
Harmonik
Ā 
Mobile raspberry pi
Mobile raspberry piMobile raspberry pi
Mobile raspberry pi
Ā 
WebRTC communication and wearable devices
WebRTC communication and wearable devicesWebRTC communication and wearable devices
WebRTC communication and wearable devices
Ā 
Multithreading development with workers
Multithreading development with workersMultithreading development with workers
Multithreading development with workers
Ā 
Ecma6 in 30 minutes
Ecma6 in 30 minutesEcma6 in 30 minutes
Ecma6 in 30 minutes
Ā 
TDD and PhoneGap
TDD and PhoneGapTDD and PhoneGap
TDD and PhoneGap
Ā 
Undoable architectures
Undoable architecturesUndoable architectures
Undoable architectures
Ā 
Test first!
Test first!Test first!
Test first!
Ā 
WebRTC and Mobile Integration
WebRTC and Mobile IntegrationWebRTC and Mobile Integration
WebRTC and Mobile Integration
Ā 
Test first
Test firstTest first
Test first
Ā 

Recently uploaded

Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Cara Menggugurkan Kandungan 087776558899
Ā 

Recently uploaded (6)

FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
Ā 
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
Ā 
Leading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdfLeading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdf
Ā 
BDSMāš”Call Girls in Sector 71 Noida Escorts >ą¼’8448380779 Escort Service
BDSMāš”Call Girls in Sector 71 Noida Escorts >ą¼’8448380779 Escort ServiceBDSMāš”Call Girls in Sector 71 Noida Escorts >ą¼’8448380779 Escort Service
BDSMāš”Call Girls in Sector 71 Noida Escorts >ą¼’8448380779 Escort Service
Ā 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Ā 
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Ā 

Develop, test and debug cross platforms apps with PhoneGap