Introduction to web api

17
Introduction to Web API

Transcript of Introduction to web api

Page 1: Introduction to web api

Introduction to Web API

Page 2: Introduction to web api

https://wiki.mozilla.org/WebAPI

Web APIs- are device compatibility and access APIs

that allow - Web apps and content to access device

hardware- access to data stored on the device

Page 3: Introduction to web api

Regular APIs• Alarm• WebActivities• PushNotifications• WebFMApi• WebPayment• IndexedDB• AmbientLightSensor• ProxyimitySensor• Notification

• ScreenOrientation• GeoLocation• MouseLock• OpenWebApps• NetworkInformation• BatteryStatus• Vibration

Page 4: Introduction to web api

Regular APIs (Contd..)

-All developers can develop apps using this API’s.-Just need to add additional line in manifest.webapp file.

Page 5: Introduction to web api

Certified APIs• WebSMS• IdleAPI• SettingsAPI• PowerManagementAPI• MobileConnectionAPI• WiFiInformationAPI

• WebBluetooth• PermissionsAPI• NetworkStatsAPI• CameraAPI• Time/ClockAPI• Attentionscreen• Voicemail

Page 6: Introduction to web api

Certified APIs (Contd ..)-Requires certification process- Only Some can develop apps using these (mostly partners alone)

Page 7: Introduction to web api

Security LevelsGranted by default• Safe web APIs that don’t expose privacy sensitive data. WebGL, fullscreen, audio, etc.Granted by user• location, camera, file system accessGranted when installed• No quota for localStorage, IndexedDB, offline cacheGranted by authorized store• Privacy and security sensitive APIs such as Contacts APIVerified by signature• Highly privileged APIs such as radio access (dialer)

Page 8: Introduction to web api

IT'S TIME to SEE SOME

Page 9: Introduction to web api

Battery Status APIvar battery = navigator.battery || navigator.mozBattery;if (battery) {var level= battery.level * 100 + '%';var Charging= battery.charging;var discharTime= battery.dischargingTime;var charTime = battery.chargingTime;

battery.addEventListener('chargingchange', function() { console.log("Battery charging? " + (battery.charging ? "Yes" : "No")); });

}

Page 10: Introduction to web api

Vibrator API// Vibrate for 1sec

window.navigator.vibrate([1000]);

// Vibrate for 5 secwindow.navigator.vibrate(5000);

// Vibrate, pause, Vibrate... window.navigator.vibrate([1000, 1000, 1000]);

// Stop Vibrationnavigator.vibrate(0);

Page 11: Introduction to web api

Notificationvar notif = navigator.mozNotification;

notif.createNotification{“title”,“message”,“image_url”}

Page 12: Introduction to web api

Using IndexDB

// open the database// 1st parameter : Database name. We are using the

name 'notesdb'// 2nd parameter is the version of the database.

var request = indexedDB.open('notesdb', 1);//avoid decimal like 1.4

Page 13: Introduction to web api

request.onsuccess = function (e) { // e.target.result has the connection to the database db = e.target.result;}

request.onerror = function (e) { console.log(e);};

Page 14: Introduction to web api

request.onupgradeneeded = function (e) { db = e.target.result; // e.target.result holds the connection to database

// create a store named 'notes' // 1st parameter is the store name // 2nd parameter is the key field that we can specify here. Here we have

opted for autoIncrement but it could be your own provided value also. var objectStore = db.createObjectStore('notes', { keyPath: 'id',

autoIncrement: true }); console.log("Object Store has been created");};

Page 15: Introduction to web api

var transaction = db.transaction([ 'notes' ], 'readwrite');var value = {}; // create an object

value.title = title;value.details = ing;value.noteDes = desc;

// add the note to the store var store = transaction.objectStore('notes'); var request = store.add(value);

Page 16: Introduction to web api

var transaction = db.transaction(["notes"]);var objectStore = transaction.objectStore("notes")objectStore.openCursor().onsuccess = function (e) {var cursor = e.target.result;

if (cursor) { var value = cursor.value;

var title =value.title var details =value.details;var notesDes =value.notesDes;// move to the next item in the cursor

cursor.continue();}

}

Page 17: Introduction to web api

Visit http://tinyurl.com/firefoxostips

mail to : [email protected]

tweet: @mozchennai @iamVP7