HTML5 Developer
@ferkhamp
fcampo
{
"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"
},
"default_locale": "en"
}
2013: 9888 APIs 7169 Mashups
Telephony
Messages
Contacts
Battery
Mobile connectivity
WiFi connectivity
Browser
Camera
Device Storage
Alarms
Keyboard
Settings
Vibration
Screen Orientation
Ambient Light
Proximity
Geolocation
Bluetooth
NFC
Hosted app
Packaged app
Web
Privileged
Certified
{
"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"
},
"type": "privileged",
"permissions": {
"alarms": {},
"browser":{},
"power":{},
"fmradio":{},
"webapps-manage":{},
"mobileconnection":{},
"bluetooth":{},
"telephony":{},
"voicemail":{},
"device-storage:sdcard":{ "access": "readonly" },
"device-storage:pictures":{ "access": "readwrite" },
"device-storage:videos":{ "access": "readwrite" },
"device-storage:music":{ "access": "readcreate" },
"device-storage:apps":{ "access": "readonly" },
"settings":{ "access": "readwrite" },
"storage":{},
"camera":{},
"geolocation":{},
"wifi-manage":{},
"desktop-notification":{},
"idle":{},
"network-events":{},
"embed-apps":{},
"background-sensors":{},
"permissions":{},
"audio-channel-notification":{},
"audio-channel-content":{},
"cellbroadcast":{},
"keyboard":{}
}
}
Full list with needed privileges on
[https://developer.mozilla.org/en-US/docs/Web/Apps/App_permissions]
First, get the object
var battery = navigator.mozBattery;
Check the current level
var batteryLevel = battery.level * 100 + "%";
Listen to events
battery.addEventLister("levelchange", setStatus, false);
battery.addEventLister("chargingchange", setStatus, false);
navigator.vibrate(1000); //one second
navigator.vibrate([1000, 200, 500]); //pattern
navigator.vibrate(0); //stop the vibration
window.addEventListener("devicelight", function(event) {
// event.value contains the detected lux values
// consider 'dim' when below 50, 'bright' above 10000
});
Available storages: 'music', 'pictures', 'videos', 'apps', 'sdcard'
var sdcard = navigator.getDeviceStorage('sdcard');
var request = sdcard.get("my-file.txt");
request.onsuccess = function () {
var file = this.result;
console.log("Found the file: " + file.name);
}
request.onerror = function () {
console.warn("Unable to get the file: " + this.error);
}
We can also check for free space
var videos = navigator.getDeviceStorage('videos');
var request = videos.usedSpace();
request.onsuccess = function () {
var size = this.result / 1000000; // Bytes to Mb
console.log("Your videos are using " + size.toFixed(2) + "Mb");
}
get the ContactManager object
var contactsAPI = navigator.mozContacts;
create a new contact
var contact = new mozContact();
contact.givenName = ["John"];
contact.familyName = ["Doe"];
contact.nickName = ["No kidding"];
save new contact into the database
var request = contactAPI.save(contact);
saving.onsuccess = function() {
console.log('New contact created');
};
saving.onerror = function(err) {
console.error(err);
};
Get the Telephony object
var tel = navigator.Telephony;
Place a call!
var call = tel.dial(“123456789”);
call.onstatechange = function (event) {
/* Different values for event.state
* "dialing", "ringing", "busy", "connecting", "connected",
* "disconnecting", "disconnected", "incoming"
*/
};
call.onconnected = function () {};
call.ondisconnected = function () {};
var messageManager = navigator.mozMobileMessage;
Send SMS or MMS
var sms = messageManager.sendSMS(number,messageContent);
var mms = messageManager.sendMMS(mmsParameters);
sms.onsucces = mms.onsuccess = function(evt) {
console.log('Thanks for paying');
};
sms.onerror = mms.onerror = function(evt) {
console.log('Problems ahead');
};
interaction
var activity = new MozActivity({
// Ask for the "pick" activity
name: "pick",
// Provide the data required by the filters of the activity
data: {
type: "image/jpeg"
}
});
activity.onsuccess = function() {
var picture = this.result;
console.log("A picture has been retrieved");
};
activity.onerror = function() {
console.log(this.error);
};
{
// [...] Other Manifest related stuff
// Activity registration
"activities": {
"pick": { // name of the activity
"href": "./pick.html", // page opened when handling
"disposition": "inline", // how is the page presented
"filters": {
"type": ["image/*","image/jpeg","image/png"] // data
},
"returnValue": true // expect a value on the response
}
}
}
navigator.mozSetMessageHandler('activity', function(activityRequest) {
var option = activityRequest.source;
if (option.name === "pick") {
// Do something to handle the activity
}
});
navigator.mozSetMessageHandler('activity', function(activityRequest) {
[...]
// Send back the result
if (picture) {
activityRequest.postResult(picture);
} else {
activityRequest.postError("Unable to provide a picture");
}
}
});
Make a call...
"dial": {
type: "webtelephony/number", // ...with the phone
number: {
regexp:/^[\\d\\s+#*().-]{0,50}$/
}
}
Create new...
"new": {
type: "webcontacts/contact" // ...contact
type: "mail" // ...email
type: "websms/sms", // ...sms
number: {
regexp:/^[\\d\\s+#*().-]{0,50}$/
}
}
Open an app...
"open": {
type: "webcontacts/contact" // ...contacts
type: [ // ...gallery
"image/jpeg",
"image/png",
"image/gif",
"image/bmp"
]
type: [ // ...music
"audio/mpeg",
"audio/ogg",
"audio/mp4"
]
}
Record media...
"record": {
type: ["photos", "videos"] // ...with the camera
}
"pick": {
"filters": {
"type": ["image/*", "image/jpeg", "image/png"]
}
}
"pick": {
"filters": {
"type": ["image/*", "image/jpeg", "image/png"]
}
}
"pick": {
"filters": {
"type": ["image/*", "image/jpeg", "image/png"]
}
}