window.ondevicelight = function (event) {
console.log("Ambient light: " + event.value + " lux");
};
W3C Specification
var battery = navigator.battery;
/*
battery.level: Battery level between 0 and 1
battery.charging: true/false
battery.chargingTime: Time left to fully charge, in seconds
battery.dischargingTime: Time until fully discharged, in seconds
*/
console.log("Battery level: " + battery.level * 100 + "%");
navigator.battery.addEventListener(
"levelchange",
function() {
// Update display with current battery level
}
);
W3C Specification
navigator.vibrate(1000);
navigator.vibrate([200, 100, 200]);
W3C Specification
// Setup Push Notifications
var reg = navigator.push.register();
reg.onsuccess = function(e) {
var endpointUrl = e.target.result;
// save endpointUrl to app server
}
navigator.mozSetMessageHandler('push', function(m) {
var version = m.version;
// do something based on version
});
//Unregister
navigator.push.unregister(endpointUrl);
SimplePush on MDN
var notification = navigator.mozNotification;
notification.createNotification(
"Title",
"Notification Text",
iconUrl
);
var appInstall = navigator.mozApps.install(manifestUrl);
appInstall.onsuccess = function(data) {
// App installed!
};
appInstall.onerror = function() {
console.log("Install failed: " + appInstall.error.name);
};
var payment = navigator.mozPay(JsonWebToken);
payment.onsuccess = function() {
// ...
// Profit!
}
var share = new MozActivity({
name: "share",
data: {
type: "image/*",
number: 1,
blobs: [new Blob($('#imgToShare')[0], {type: "text/png"})]
}
});
share.onsuccess = function() {
// Do stuff
};
share.onerror = function () {
// handle error
};
"pick": {
"href": "./pick.html",
"disposition": "inline",
"filters": {
"type": ["image/*","image/jpeg","image/png"]
},
"returnValue": true
}
navigator.mozSetMessageHandler('activity', function(request) {
var options = request.source;
if ("pick" === options.name) {
// Do something with the image
}
});
{
"name": "Cool App",
"description": "This app lets you do really awesome stuff"
}
{
"name": "Cool App",
"description": "This app lets you do really awesome stuff",
"icons": {
"60": "/img/icon-60.png",
"128": "/img/icon-128.png"
},
"fullscreen": true,
"orientations": ["portrait","landscape-secondary"],
"chrome": { "navigation": true},
"developer": {
"name": "Colin Frei",
"url": "http://colinfrei.com"
}
}
Firefox OS App Icon Guidelines
"chrome": { "navigation": true}
{
"name": "Cool App",
"description": "This app lets you do really awesome stuff",
"default_locale": "en",
"locales": {
"de": {
"description": "Beschreibung der App"
}
}
}
{
"name": "Cool App",
"description": "This app lets you do really awesome stuff",
"activities": {
"pick": {
"href": "./pick.html",
"disposition": "inline",
"filters": {
"type": ["image/*","image/jpeg","image/png"]
},
"returnValue": true
}
}
}
{
"name": "Cool App",
"description": "This app lets you do really awesome stuff",
"messages": [
{ "notification": "/dialer/index.html#keyboard-view" },
{ "alarm": "/facebook/fb_sync.html" }
]
}
{
"name": "Cool App",
"description": "This app lets you do really awesome stuff",
"installs_allowed_from": [
"https://marketplace.firefox.com",
"http://colinfrei.com"
]
}
{
"name": "App Name",
"description": "A description of your app",
"type": "privileged",
"permissions": {
"desktop-notification": {
"description": "Required to notify about stuff"
}
}
}
Web | Privileged | Certified | |
Hosted | ✔ | ✖ | ✖ |
Packaged | ✔ | ✔ | ✔ |
{
"name": "App Name",
"description": "A description of your app",
"type": "privileged",
"permissions": {
"contacts": {
"description": "Required to match users",
"access": "readonly"
}
}
}
{
"name": "App Name",
"description": "A description of your app",
"version": "2.0"
}
Content Type:
application/x-web-app-manifest+json
Same Origin
Absolute Paths