OK, I've been trying to get this to work for a day now, and I know I'm
missing something. Could someone post their working code? I've got
index.html and gap.js in the www folder, and an audio file 10 seconds
long in both the www folder and resources folder. My index.html and
gap.js code is below. Is there something I'm missing?
This is what I have for my index.html in the www folder:
<html>
<head>
<title>Phone Gap Offline</title>
<meta http-equiv="content-type" content="text/html;
charset=utf-8">
<meta name="viewport" content="minimum-scale=1.0, width=device-
width, maximum-scale=1.1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="YES">
<script type="text/javascript" src="gap.js"></script>
<LINK href="phone.css" rel="stylesheet" type="text/css">
</head>
<body onload="initGap();">
<img src="test.png" onclick="Device.playSound('test.wav');">
</body>
</html>
// Utils
try {
$ // Test if it is alread used
} catch(e) {
$ = function(id){
return document.getElementById(id)
};
}
// Acceleration Handling
var accelX = 0;
var accelY = 0;
var accelZ = 0;
function gotAcceleration(x,y,z){
x = eval(x);
y = eval(y);
z = eval(z);
if ((!isNaN(x)) && (!isNaN(y)) && (!isNaN(z))) {
accelX = x;
accelY = y;
accelZ = z;
}
return x + " " + y + " " + z;
}
// A little more abstract
var DEBUG = true;
if (!window.console || !DEBUG) {
console = {
log: function(){
},
error: function(){
}
}
}
var Device = {
available: false,
model: "",
version: "",
uuid: "",
isIPhone: null,
isIPod: null,
init: function(model, version) {
try {
Device.available = __gap;
Device.model = __gap_device_model;
Device.version = __gap_device_version;
Device.gapVersion = __gap_version;
Device.uuid = __gap_device_uniqueid;
} catch(e) {
alert("GAP is not supported!")
}
},
exec: function(command) {
if (Device.available) {
try {
document.location = "gap:" + command;
} catch(e) {
console.log("Command '" + command + "' has not been
executed, because of exception: " + e);
alert("Error executing command '" + command + "'.")
}
}
},
Location: {
// available: true,
lon: null,
lat: null,
callback: null,
init: function() {
Device.exec("getloc");
},
set: function(lat, lon) {
Device.Location.lat = lat;
Device.Location.lon = lon;
if(Device.Location.callback != null) {
Device.Location.callback(lat, lon)
Device.Location.callback = null;
}
},
wait: function(func) {
Device.Location.callback = func
Device.exec("getloc");
}
},
Image: {
//available: true,
callback: null,
getFromPhotoLibrary: function() {
return Device.exec("getphoto" + ":" +
Device.Image.callback)
},
getFromCamera: function() {
return Device.exec("getphoto" + ":" +
Device.Image.callback)
},
getFromSavedPhotosAlbum: function() {
return Device.exec("getphoto" + ":" +
Device.Image.callback)
}
},
vibrate: function() {
return Device.exec("vibrate")
},
playSound: function(clip) {
return Device.exec('sound:' + clip);
}
}
function gotLocation(lat, lon) {
return Device.Location.set(lat, lon)
}