PhoneGap: Accessing Device Capabilities

  • 1,176 views
Uploaded on

PhoneGap: Accessing Device Capabilities …

PhoneGap: Accessing Device Capabilities

This presentation has been developed in the context of the Mobile Applications Development course, DISIM, University of L'Aquila (Italy), Spring 2013.

http://www.ivanomalavolta.com

More in: Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,176
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
64
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. navigator.device.capture•••
  • 2. navigator.device.capture
  • 3. –––––
  • 4. var imageModes =navigator.device.capture.supportedImageModes;for each (var mode in imageModes) {console.log(mode.type);console.log(mode.height);console.log(mode.width);}
  • 5. capture
  • 6. • • 
  • 7. var options = { limit: 2, duration: 5 };navigator.device.capture.captureAudio(win, fail, options);function win(mediaFiles) {var i;for (i=0; i<mediaFiles.length; i++) {console.log(mediaFiles[i]);}}function fail(error) {console.log(„Error with code: + error.code);}
  • 8. captureAudio
  • 9. • 
  • 10. var options = { limit: 3};navigator.device.capture.captureImage(win, fail,options);function win(mediaFiles) {var i;for (i=0; i<mediaFiles.length; i++) {upload(mediaFiles[i]);}}function fail(error) {console.log(„Error with code: + error.code);}
  • 11. captureAudio
  • 12. • • 
  • 13. navigator.device.capture.captureVideo(win, fail, {});function win(mediaFiles) {var i;for (i=0; i<mediaFiles.length; i++) {upload(mediaFiles[i]);}}function fail(error) {console.log(„Error with code: + error.code);}
  • 14. CaptureError.CAPTURE_INTERNAL_ERRCaptureError.CAPTURE_APPLICATION_BUSYCaptureError.CAPTURE_INVALID_ARGUMENTCaptureError.CAPTURE_NO_MEDIA_FILESCaptureError.CAPTURE_NOT__SUPPORTED
  • 15. getPicture()••
  • 16. navigator.camera.getPicture(win, fail,{ quality: 50,destinationType: destinationType.FILE_URI,pictureSource.PHOTOLIBRARY});function win(imageURI) {var element = $(“#block”);element.src(imageURI);}// fail function omitted here
  • 17. navigator.contactsnavigator.contacts••
  • 18. navigator.contacts.create(properties)
  • 19. navigator.contacts.create(properties)propertiesvar contact = navigator.contacts.create({"displayName": “Ivano“});
  • 20. contacts.find
  • 21. •••
  • 22. var contact = navigator.contacts.create({"displayName": “Ivano“});var name = new ContactName();name.givenName = “Ivano“;name.familyName = “Malavolta“;contact.name = name;contact.birthday = new Date(“19 July 1983");contact.save(win, fail);function win(contact) {alert("Save Success");};function fail(contactError) {alert("Error = " + contactError.code);};
  • 23. navigator.contacts.find(contactFields,contactSuccess,contactError,contactFindOptions);
  • 24. var fields = ["displayName", "name"]; // or [“*”]navigator.contacts.find(fields, win, fail);function win(contacts) {console.log(„ok);};function fail(err) {console.log(err.code);};
  • 25. var options = new ContactFindOptions();options.filter = “Ivano";options.multiple = true;filter = ["displayName",“birthday"];navigator.contacts.find(filter, win, fail, options);function win(contacts) {for (var i=0; i<contacts.length; i++) {console.log(contacts[i].displayName);}};function fail(contactError) {alert("Error = " + contactError.code);};
  • 26. failContactError.UNKNOWN_ERRORContactError.INVALID_ARGUMENT_ERRORContactError.TIMEOUT_ERRORContactError.PENDING_OPERATION_ERRORContactError.IO_ERRORContactError.NOT_SUPPORTED_ERRORContactError.PERMISSION_DENIED_ERROR
  • 27. – ontouchstart, onclick, ...
  • 28. document.addEventListener(EVENTNAME, onEvent, false);function onEvent() {// handle the event}
  • 29. • deviceready• pause, resume• online, offline• batterycritical, batterylow, batterystatus• backbutton, menubutton, searchbutton• startcallbutton, endcallbutton• volumedownbutton, volumeupbutton
  • 30. ••deviceready
  • 31. pauseresume
  • 32. onlineoffline
  • 33. navigator.network.connectiontypeConnection.UNKNOWNConnection.ETHERNETConnection.WIFIConnection.CELL_2GConnection.CELL_3GConnection.CELL_4GConnection.NONE
  • 34. batterycriticalbatterylowbatterycriticalbatterystatus
  • 35. backbuttonmenubuttonsearchbutton
  • 36. •••••
  • 37. navigator.notification.alert(message,callback, [title], [button])••••
  • 38. navigator.notification.alert(message,callback, [title], [buttons])••–••
  • 39. navigator.notification.prompt(message,callback, [title], [buttons])••–••
  • 40. navigator.notification.beep(times)•
  • 41. navigator.notification.vibrate(milliseconds)•
  • 42. navigator.accelerometer•••
  • 43. getCurrentAcceleration(win, fail);
  • 44. var watchID =navigator.accelerometer.watchAcceleration(win, fail,[options]);
  • 45. clearWatch(watchID);
  • 46. these values include the effect ofgravity (9.81 m/s^2)
  • 47. var options = { frequency: 3000 };var watchID = navigator.accelerometer.watchAcceleration(win, fail,options);function win(acc) {if((acc.x == 0) && (acc.y == 0) && (acc.z == 9,81)) {console.log(“I am on a table”);stop();}}function fail() {console.log(“error”);}function stop() {if(watchID) {navigator.accelerometer.clearWatch(watchID);watchID = null;}}
  • 48. var previousReading = {x: null, y: null, z: null};navigator.accelerometer.watchAcceleration(function (reading) {var changes = {},bound = 3;if (previousReading.x !== null) {changes.x = Math.abs(previousReading.x, reading.x);changes.y = Math.abs(previousReading.y, reading.y);changes.z = Math.abs(previousReading.z, reading.z);}if (changes.x > bound && changes.y > bound && changes.z > bound) {console.log(“shake detected”);}previousReading = {x: reading.x,y: reading.y,z: reading.z}}, null, { frequency: 300 });