Jason Weathersby, Technical Evangelist, Mozilla @JasonWeathersby or jweathersby@mozilla.com
{
"name": "My App",
"description": "My elevator pitch goes here",
"launch_path": "/",
"icons": { "128": "/img/icon-128.png" },
"developer": {
"name": "Your name or organization",
"url": "http://your-homepage-here.org"
}
}
var b = navigator.battery;
if (b) {
var level = Math.round(b.level * 100) + "%",
charging = (b.charging) ? "" : "not ",
chargeTime = parseInt(b.chargingTime / 60, 10),
dischargeTime = parseInt(b.dischargingTime/60,10);
b.addEventListener("levelchange", show);
b.addEventListener("chargingchange", show);
b.addEventListener("chargingtimechange", show);
b.addEventListener("dischargingtimechange", show);
}
navigator.geolocation.getCurrentPosition(function (position) {
geo.innerHTML = "Lat:" +
position.coords.latitude +
", Long:" + position.coords.longitude;
},
function () {
geo.innerHTML = "Failed...";
});
Need permissions in webapp.manifest."permissions": {
"geolocation": {
"description" : "location"
}
}
var myWorker = new Worker("js/worker.js");
myWorker.onmessage = function (oEvent) {
alert("Worker said : " + oEvent.data);
};
myWorker.postMessage("John");
//worker.js
onmessage = function (oEvent) {
self.setTimeout(
function() {
postMessage("Hi " + oEvent.data);
}, Math.random() * 2000 + 1000);
};
var p1 = new Promise(
function(resolve, reject) {
window.setTimeout(
function() {
var secs = Math.random() * 2000 + 1000;
resolve(secs / 1000);
}, secs);
});
p1.then(
function(val) {
alert("promise done in " + val + " secs");
});
"type": "privileged"
var contact = new mozContact();
contact.init({name: "William"});
var request = navigator.mozContacts.save(contact);
request.onsuccess = function() {
// contact generated
};
request.onerror = function() {
// contact generation failed
};
Permission must be set in manifest.webapp"contacts":{ "access": "readwrite" },
"activities": {
"pick": {
"filters": {
"type": ["image/*", "image/jpeg", "image/png"]
},
"disposition": "inline"
"returnValue": true,
"href": "/index.html#pick"
},
navigator.mozSetMessageHandler('activity',function(activityRequest) {
var option = activityRequest.source;
if (activityRequest.source.name === "pick") {
// Do something to handle the activity
if (picture) {
activityRequest.postResult(picture);
} else {
activityRequest.postError("Unable to provide a picture");
}
}
});
var activity = new MozActivity({
name: "pick",
// Provide the data required by the
//filter of the activity
data: {
type: "image/jpeg"
}
});
activity.onsuccess = function () {
var img = document.createElement("img");
if (this.result.blob.type.indexOf("image") != -1) {
img.src = window.URL.createObjectURL(this.result.blob);
}
};
activity.onerror = function () { // error
};
var call = new MozActivity({
name: "dial",
data: {
number: "+46777888999"
}
});
Install App - Mac Examplecurl "https://controller.apk.firefox.com/application.apk? manifestUrl=
https://marketplace.firefox.com/app/
c599acd5-2ced-42b7-a5a9-0096a8da6176/manifest.webapp"
-o "bumpertest.apk" && adb install bumpertest.apk
Full or Partial Support for 15 Plugins
Battery Status | Full Support (next version) | Camera | Partial Support |
Console | Full Support | Contacts | Partial Support |
Device | Partial Support | Device Motion | Full Support |
Device Orientation | Partial Support | Dialogs | Full Support |
File | Partial Support | File Transfer | Partial Support |
Geolocation | Full Support | Globalization | Partial Support |
In App Browser | Partial Support | Media | Not Supported |
Media Capture | Not Supported | Network Information | Full Support |
Splashscreen | Not Applicable | Statusbar | Not Applicable |
Vibration | Full Support |
Implementsnavigator.camera.getPicture();
caveat: Implemented with MozActivitynavigator.camera.getPicture(function (src) {
var img = document.createElement('img');
img.src = src;
}, function () {},
{destinationType: 1}
);
Implements the following methods:
var options = {
frequency: 50
};
watchIDAccel = navigator.accelerometer.
watchAcceleration(onSuccess, onError, options);
function onSuccess(acceleration) {
var acX = acceleration.x.toFixed(1) * -1;
var acY = acceleration.y.toFixed(1);
var acZ = acceleration.z.toFixed(1);
....
Implements the following methods:
var options = {
frequency: 300
};
watchID = navigator.compass.
watchHeading(onSuccess, onError, options);
function onSuccess(heading) {
myHeading =
(heading.magneticHeading).toFixed(2);
....
This plugin provides location informationnavigator.geolocation.
getCurrentPosition(onSuccess, onError);
var onSuccess = function (position) {
var geodata = [position.coords.latitude,
position.coords.longitude, 2, 2];
...
}
This plugin provides browser within the app
browserRef = window.open(
'https://developer.mozilla.org',
'_blank', 'location=yes');
var el = document.
querySelector(".inAppBrowserWrap");
setOutput(el);
$ sudo npm install -g cordova
$ cordova create hello com.example.hello HelloWorld
$ cd hello
$ cordova platform add firefoxos
$ cordova prepare firefoxos
//add device specific plugins
$ cordova plugin add org.apache.cordova.geolocation
Social Apps