Introduction to web api
-
Upload
viswaprasath-ks -
Category
Mobile
-
view
250 -
download
0
Transcript of Introduction to web api
![Page 1: Introduction to web api](https://reader036.fdocuments.net/reader036/viewer/2022081806/55a51ba91a28ab565a8b465a/html5/thumbnails/1.jpg)
Introduction to Web API
![Page 2: Introduction to web api](https://reader036.fdocuments.net/reader036/viewer/2022081806/55a51ba91a28ab565a8b465a/html5/thumbnails/2.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081806/55a51ba91a28ab565a8b465a/html5/thumbnails/3.jpg)
Regular APIs• Alarm• WebActivities• PushNotifications• WebFMApi• WebPayment• IndexedDB• AmbientLightSensor• ProxyimitySensor• Notification
• ScreenOrientation• GeoLocation• MouseLock• OpenWebApps• NetworkInformation• BatteryStatus• Vibration
![Page 4: Introduction to web api](https://reader036.fdocuments.net/reader036/viewer/2022081806/55a51ba91a28ab565a8b465a/html5/thumbnails/4.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081806/55a51ba91a28ab565a8b465a/html5/thumbnails/5.jpg)
Certified APIs• WebSMS• IdleAPI• SettingsAPI• PowerManagementAPI• MobileConnectionAPI• WiFiInformationAPI
• WebBluetooth• PermissionsAPI• NetworkStatsAPI• CameraAPI• Time/ClockAPI• Attentionscreen• Voicemail
![Page 6: Introduction to web api](https://reader036.fdocuments.net/reader036/viewer/2022081806/55a51ba91a28ab565a8b465a/html5/thumbnails/6.jpg)
Certified APIs (Contd ..)-Requires certification process- Only Some can develop apps using these (mostly partners alone)
![Page 7: Introduction to web api](https://reader036.fdocuments.net/reader036/viewer/2022081806/55a51ba91a28ab565a8b465a/html5/thumbnails/7.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081806/55a51ba91a28ab565a8b465a/html5/thumbnails/8.jpg)
IT'S TIME to SEE SOME
![Page 9: Introduction to web api](https://reader036.fdocuments.net/reader036/viewer/2022081806/55a51ba91a28ab565a8b465a/html5/thumbnails/9.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081806/55a51ba91a28ab565a8b465a/html5/thumbnails/10.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081806/55a51ba91a28ab565a8b465a/html5/thumbnails/11.jpg)
Notificationvar notif = navigator.mozNotification;
notif.createNotification{“title”,“message”,“image_url”}
![Page 12: Introduction to web api](https://reader036.fdocuments.net/reader036/viewer/2022081806/55a51ba91a28ab565a8b465a/html5/thumbnails/12.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081806/55a51ba91a28ab565a8b465a/html5/thumbnails/13.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081806/55a51ba91a28ab565a8b465a/html5/thumbnails/14.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081806/55a51ba91a28ab565a8b465a/html5/thumbnails/15.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081806/55a51ba91a28ab565a8b465a/html5/thumbnails/16.jpg)
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();}
}