PhoneGap: Accessing Device Capabilities
Upcoming SlideShare
Loading in...5
×
 

PhoneGap: Accessing Device Capabilities

on

  • 1,579 views

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

Statistics

Views

Total Views
1,579
Views on SlideShare
1,388
Embed Views
191

Actions

Likes
1
Downloads
59
Comments
0

1 Embed 191

http://www.ivanomalavolta.com 191

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

PhoneGap: Accessing Device Capabilities PhoneGap: Accessing Device Capabilities Presentation Transcript

  • navigator.device.capture•••
  • navigator.device.capture
  • –––––
  • var imageModes =navigator.device.capture.supportedImageModes;for each (var mode in imageModes) {console.log(mode.type);console.log(mode.height);console.log(mode.width);}
  • capture
  • • • 
  • 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);}
  • captureAudio
  • • 
  • 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);}
  • captureAudio
  • • • 
  • 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);}
  • CaptureError.CAPTURE_INTERNAL_ERRCaptureError.CAPTURE_APPLICATION_BUSYCaptureError.CAPTURE_INVALID_ARGUMENTCaptureError.CAPTURE_NO_MEDIA_FILESCaptureError.CAPTURE_NOT__SUPPORTED
  • getPicture()••
  • 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
  • navigator.contactsnavigator.contacts••
  • navigator.contacts.create(properties)
  • navigator.contacts.create(properties)propertiesvar contact = navigator.contacts.create({"displayName": “Ivano“});
  • contacts.find
  • •••
  • 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);};
  • navigator.contacts.find(contactFields,contactSuccess,contactError,contactFindOptions);
  • var fields = ["displayName", "name"]; // or [“*”]navigator.contacts.find(fields, win, fail);function win(contacts) {console.log(„ok);};function fail(err) {console.log(err.code);};
  • 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);};
  • failContactError.UNKNOWN_ERRORContactError.INVALID_ARGUMENT_ERRORContactError.TIMEOUT_ERRORContactError.PENDING_OPERATION_ERRORContactError.IO_ERRORContactError.NOT_SUPPORTED_ERRORContactError.PERMISSION_DENIED_ERROR
  • – ontouchstart, onclick, ...
  • document.addEventListener(EVENTNAME, onEvent, false);function onEvent() {// handle the event}
  • • deviceready• pause, resume• online, offline• batterycritical, batterylow, batterystatus• backbutton, menubutton, searchbutton• startcallbutton, endcallbutton• volumedownbutton, volumeupbutton
  • ••deviceready
  • pauseresume
  • onlineoffline
  • navigator.network.connectiontypeConnection.UNKNOWNConnection.ETHERNETConnection.WIFIConnection.CELL_2GConnection.CELL_3GConnection.CELL_4GConnection.NONE
  • batterycriticalbatterylowbatterycriticalbatterystatus
  • backbuttonmenubuttonsearchbutton
  • •••••
  • navigator.notification.alert(message,callback, [title], [button])••••
  • navigator.notification.alert(message,callback, [title], [buttons])••–••
  • navigator.notification.prompt(message,callback, [title], [buttons])••–••
  • navigator.notification.beep(times)•
  • navigator.notification.vibrate(milliseconds)•
  • navigator.accelerometer•••
  • getCurrentAcceleration(win, fail);
  • var watchID =navigator.accelerometer.watchAcceleration(win, fail,[options]);
  • clearWatch(watchID);
  • these values include the effect ofgravity (9.81 m/s^2)
  • 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;}}
  • 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 });