This presentation has been developed in the context of the Mobile Applications Development course at the Computer Science Department of the University of L’Aquila (Italy).
The audio recording formats supported by the device supportedImageModes supportedImageModes supportedImageModes supportedImageModes The recording image sizes and formats supported by the device the device supportedVideoModes supportedVideoModes supportedVideoModes supportedVideoModes The recording video resolutions and formats supported by the device They all contain an array of ConfigurationData ConfigurationData ConfigurationData ConfigurationData objects
capture modes media capture modes media capture modes supported by the device Properties: 1. 1. 1. 1. Type Type Type Type: String The string in lower case representing the media type The string in lower case representing the media type – video/3gpp – video/quicktime – image/jpeg – audio/amr – audio/wav
The height of the image or video in pixels The height of the image or video in pixels 3. 3. 3. 3. width width width width: integer The width of the image or video in pixels In the case of a sound clip, the value of these attributes In the case of a sound clip, the value of these attributes is 0
operation asynchronous operation to capture audio recordings recordings It uses the device's default audio recording default audio recording default audio recording default audio recording app app app app The operation allows the device user to capture multiple recordings multiple recordings multiple recordings multiple recordings in a single session multiple recordings multiple recordings multiple recordings multiple recordings in a single session
invoke the CaptureCB CaptureCB CaptureCB CaptureCB callback with an array the CaptureCB CaptureCB CaptureCB CaptureCB callback with an array of MediaFile objects If the operation is terminated by the user before an audio clip is captured, the CaptureErrorCB CaptureErrorCB CaptureErrorCB CaptureErrorCB callback will be invoked callback will be invoked
limit limit limit limit (not supported in iOS only 1 recording at a time) The maximum number of audio clips the device user can record in a single capture operation • Duration Duration Duration Duration (not supported in Android unlimited) • Duration Duration Duration Duration (not supported in Android unlimited) The maximum duration of an audio sound clip, in seconds • Mode Mode Mode Mode (not supported in Android and iOS) The selected audio mode, it must match one of the elements in capture.supportedAudioModes audio/wav audio/amr
operation asynchronous operation to capture images images It uses the device camera application device camera application device camera application device camera application The operation allows the device user to capture multiple multiple multiple multiple images images images images in a single session multiple multiple multiple multiple images images images images in a single session
finished, it will invoke the CaptureCB CaptureCB CaptureCB CaptureCB callback with an array of MediaFile objects If the operation is terminated by the user before any If the operation is terminated by the user before any image is captured, the CaptureErrorCB CaptureErrorCB CaptureErrorCB CaptureErrorCB callback will be invoked
limit limit limit limit (not supported in iOS only 1 image at a time) The maximum number of images the device user can capture in a single capture operation • Mode Mode Mode Mode (not supported in Android and iOS image/jpeg only) The selected image mode, it must match one of the elements in capture.supportedImageModes
navigator.device.capture.captureImage(win, fail, options); function win(mediaFiles) { var i; for (i=0; i<mediaFiles.length; i++) { upload(mediaFiles[i]); } } It is very similar to the audio example! } function fail(error) { console.log(‘Error with code: ' + error.code); }
operation asynchronous operation to record videos It uses the device video recording application device video recording application device video recording application device video recording application The operation allows the device user to capture multiple multiple multiple multiple recordings recordings recordings recordings in a single session
finished, it will invoke the CaptureCB CaptureCB CaptureCB CaptureCB callback with an array of MediaFile objects If the operation is terminated by the user before any If the operation is terminated by the user before any video is recorded, the CaptureErrorCB CaptureErrorCB CaptureErrorCB CaptureErrorCB callback will be invoked
limit limit limit limit (not supported in iOS only 1 video at a time) The maximum number of video clips the device user can record in a single capture operation • duration duration duration duration (not supported in Android and iOS unlimited) • duration duration duration duration (not supported in Android and iOS unlimited) The maximum duration of a video clip, in seconds • m m m mode ode ode ode (not supported in Android and iOS) The selected video recording mode, it must match one of the elements in capture.supportedVideoModes video/quicktime video/3gpp
{ var i; for (i=0; i<mediaFiles.length; i++) { upload(mediaFiles[i]); } } It is very similar to the image & audio examples! } function fail(error) { console.log(‘Error with code: ' + error.code); }
file Name Name Name Name (String) The name of the file, without path information fullPath fullPath fullPath fullPath (String) The full path of the file, including the name Type Type Type Type (String) Type Type Type Type (String) The mime type lastModifiedDate lastModifiedDate lastModifiedDate lastModifiedDate (Date) The date and time that the file was last modified Size Size Size Size (Integer) The size of the file, in bytes
media capture operation media capture operation It contains a pre pre pre pre- - - -defined defined defined defined error error error error code code code code CaptureError.CAPTURE_INTERNAL_ERR CaptureError.CAPTURE_APPLICATION_BUSY CaptureError.CAPTURE_APPLICATION_BUSY CaptureError.CAPTURE_INVALID_ARGUMENT CaptureError.CAPTURE_NO_MEDIA_FILES CaptureError.CAPTURE_NOT__SUPPORTED
• a base64 encoded string, or • the URI of an image file Encoding the image using Base64 has caused memory Encoding the image using Base64 has caused memory issues on some of these devices it is recommended to use the URI of the image file
to the photo album on the device after Save the image to the photo album on the device after capture Every platform has its own quirks, you better check Every platform has its own quirks, you better check them on the Cordova documentation
destinationType: destinationType.FILE_URI, pictureSource.PHOTOLIBRARY }); function win(imageURI) { var element = $(“#block”); element.src(imageURI); element.src(imageURI); } // fail function omitted here
to the device contacts DB You can call 2 methods on You can call 2 methods on navigator.contacts • contacts.create contacts.create contacts.create contacts.create • contacts.find contacts.find contacts.find contacts.find
function that returns a new Contact Contact Contact Contact object To persist the Contact object to the device, you have to invoke the Contact.save method to invoke the Contact.save method
a user contact It represents a user contact It represents a user contact A contact can be created, saved or removed from the device contacts database The contacts.find method is used for retrieving one or more Contacts from the device contacts database or more Contacts from the device contacts database
clone() clone() clone() clone() • clone() clone() clone() clone() Returns a new Contact object that is a deep copy of the calling object, its id property is null • remove(win, fail) remove(win, fail) remove(win, fail) remove(win, fail) Removes the contact from the device contacts database Removes the contact from the device contacts database • save(win, fail) save(win, fail) save(win, fail) save(win, fail) Saves a new contact to the device contacts database, or updates an existing contact if a contact with the same id id id id already exists
is an asyncronous asyncronous asyncronous asyncronous function that queries the device It is an asyncronous asyncronous asyncronous asyncronous function that queries the device contacts database and returns an array of Contact Contact Contact Contact objects
be used as search qualifier. Only these Contact fields to be used as search qualifier. Only these fields will have values in the resulting Contact objects contactSuccess contactSuccess contactSuccess contactSuccess Success callback function that is invoked with the array of contacts returned from the contacts database contactError contactError contactError contactError [optional] Error callback function contactFindOptions contactFindOptions contactFindOptions contactFindOptions [Optional] Search options to filter contacts
Contact objects resulting from a find operation objects resulting from a find operation var fields = ["displayName", "name"]; // or [“*”] navigator.contacts.find(fields, win, fail); function win(contacts) { function win(contacts) { console.log(‘ok'); }; function fail(err) { console.log(err.code); };
filter the results Properties Properties Properties Properties filter filter filter filter (String) (Default: "") The search string used to find contacts A case-insensitive, partial value match is applied to each A case-insensitive, partial value match is applied to each field specified in the contactFields contactFields contactFields contactFields parameter multiple multiple multiple multiple (Boolean) (default: false) Determines if the find operation should return multiple contacts
by your Javascript code Javascript code In traditional JS programs, any element of the page can have certain events – ontouchstart, onclick, ... – ontouchstart, onclick, ...
use an event listener document.addEventListener(EVENTNAME, onEvent, false); function onEvent() { // handle the event } EVENTNAME is the name of the event you want to listen to onEvent() is the callback function triggered every time the event is fired
Cordova app Cordova consists of two code bases: Cordova consists of two code bases: • native • JavaScript Once deviceready is fired, you know two things: 1. The DOM has loaded 1. The DOM has loaded 2. the Cordova native API are loaded too Only at this point you can try to call Cordova APIs
the WP emulator, the connection.status of the device is always unknown online fires when the application's network connection changes to being online (that is, it is connected to the Internet) device is always unknown the online event will NOT fire offline fires when the application's network connection changes to being offline (that is, no Internet connection available)
you have to use the navigator.network.connection object use the navigator.network.connection object It has a type property with one of the following values: Connection.UNKNOWN Connection.ETHERNET Connection.ETHERNET Connection.WIFI Connection.CELL_2G Connection.CELL_3G Connection.CELL_4G Connection.NONE
batterycritical fires when the battery has reached the critical level threshold batterylow similar to , but with a higher threeshold this value is device-specific similar to batterycritical, but with a higher threeshold batterystatus fires a change in the battery status is detected the battery status must change of at least 1%
called with an object that contains two properties: level level level level (Integer) The percentage of battery (0-100) isPlugged isPlugged isPlugged isPlugged (Boolean) Represents whether or not the device is plugged in or not
when the user presses the “back” button menubutton fires when the user presses the “menu” button fires when the user presses the “menu” button searchbutton fires when the user presses the “search” button
motion in the x, y, and z direction You can call 3 methods on it: You can call 3 methods on it: • accelerometer.getCurrentAcceleration accelerometer.getCurrentAcceleration accelerometer.getCurrentAcceleration accelerometer.getCurrentAcceleration • accelerometer.watchAcceleration accelerometer.watchAcceleration accelerometer.watchAcceleration accelerometer.watchAcceleration • accelerometer.clearWatch accelerometer.clearWatch accelerometer.clearWatch accelerometer.clearWatch
and z axis axis getCurrentAcceleration(win, fail); win win win win callback function with an Acceleration Acceleration Acceleration Acceleration parameter fail fail fail fail error callback
interval var watchID = navigator.accelerometer.watchAcceleration(win, fail, [options]); win win win win callback function with an Acceleration Acceleration Acceleration Acceleration parameter, it is called at regular intervals fail fail fail fail fail fail fail fail error callback options options options options the interval is specified in the frequency parameter
parameter watch ID parameter clearWatch(watchID); watchID watchID watchID watchID ID returned by accelerometer.watchAcceleration ID returned by accelerometer.watchAcceleration
in time point in time Properties Properties Properties Properties x x x x (Number) Amount of acceleration on the x-axis. (in m/s^2) y y y y (Number) these values include the effect of gravity (9.81 m/s^2) Amount of acceleration on the y-axis. (in m/s^2) z z z z (Number) Amount of acceleration on the z-axis. (in m/s^2) timestamp timestamp timestamp timestamp (Timestamp) Creation timestamp in milliseconds