Introduction to web api
-
Upload
viswaprasath-ks -
Category
Mobile
-
view
247 -
download
0
Transcript of Introduction to web api
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
Regular APIs• Alarm• WebActivities• PushNotifications• WebFMApi• WebPayment• IndexedDB• AmbientLightSensor• ProxyimitySensor• Notification
• ScreenOrientation• GeoLocation• MouseLock• OpenWebApps• NetworkInformation• BatteryStatus• Vibration
Regular APIs (Contd..)
-All developers can develop apps using this API’s.-Just need to add additional line in manifest.webapp file.
Certified APIs• WebSMS• IdleAPI• SettingsAPI• PowerManagementAPI• MobileConnectionAPI• WiFiInformationAPI
• WebBluetooth• PermissionsAPI• NetworkStatsAPI• CameraAPI• Time/ClockAPI• Attentionscreen• Voicemail
Certified APIs (Contd ..)-Requires certification process- Only Some can develop apps using these (mostly partners alone)
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)
IT'S TIME to SEE SOME
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")); });
}
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);
Notificationvar notif = navigator.mozNotification;
notif.createNotification{“title”,“message”,“image_url”}
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
request.onsuccess = function (e) { // e.target.result has the connection to the database db = e.target.result;}
request.onerror = function (e) { console.log(e);};
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");};
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);
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();}
}