PhoneGap allows developers to build native mobile apps using HTML, CSS and JavaScript. It works by wrapping web-based apps so they can access device APIs and be deployed to app stores. Developers build their app once using web standards, then PhoneGap packages it to run on multiple platforms like Android, iOS and Windows Phone. The document provides instructions for building basic PhoneGap apps for Android, iOS and Windows Phone, accessing device APIs, and deploying apps to stores.
9. APIs-Storage
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}
function errorCB(err) {
alert("Error processing SQL: "+err.code);
}
function successCB() {
alert("success!");
}
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
db.transaction(populateDB, errorCB, successCB);
10. APIs-Storage
function queryDB(tx) {
tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
}
function querySuccess(tx, results) {
varlen = results.rows.length;
console.log("DEMO table: " + len + " rows found.");
for (vari=0; i<len; i++){console.log("Row = " + i + " ID = " + results.rows.item(i).id + " Data = " +
results.rows.item(i).data);
}
}
function errorCB(err) {
alert("Error processing SQL: "+err.code);
}
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
db.transaction(queryDB, errorCB);
11. Demonstration
• Download and install PhoneGap
– http://phonegap.com/
• Develop your web application and wrap it
with Phonegap
• Drop www to target platform projects
• Test/Run
• Deploy it!
12. Android demo
1. Requirements
– Eclipse 3.4+
2. Install SDK + PhoneGap
– Download and install Eclipse Classic
– Download and install Android SDK
– Download and install ADT Plugin
– Donwload the latest copy of PhoneGap and
extract its contents.
14. Android demo continue…
5. Copy from phonegap root/libs/android
– example/assets/www/* to assets/www
– cordova-1.5.0.jar to libs/
– xml folder to /res
16. Android demo continue…
5. Refresh the project
6. Update activity code
– Add cordova.jar into build path
– Change the class's extend from Activity to DroidGap
– Replace the setContentView() line with
super.loadUrl("file:///android_asset/www/index.ht
ml");
– Add import org.apache.cordova.DroidGap;
– Add import com.phonegap.*;
– Remove import android.app.Activity;
17. iPhone Demo
• InstallXcode
• Install PhoneGap
– Open and install from Cordova-1.5.0.dmg
• Create a new project
• Select PhoneGap/cordova-based Application
• Run it
• Drag the www directory by the iosphonegap project
directory into project
• Run it again
• Copy the html files developed from Android into the ios
project www directory
• Run it again
18. Windows phone demo
• Require Windows 7 or Windows Vista with SP2
• JDK 32bit
• Install
– Windows Phone SDK and phonegap
• Setup
– Open Visual Studio Express for Windows Phone and
choose New Project.
– Select PhoneGapStarter.
– Drag www folder and drop into project
– Copy the app related files into www folder
• Build and run
19. PhoneGap for Mobile Application
Development
Yiguang Hu
yighu@yahoo.com
yighu@twitter