Working with PhoneGap

By High School Technology Services myhsts.org Recap From Previous Session

In previous session we introduced you to PhoneGap/Cordova. We covered – . The Role of Cordova/PhoneGap Libraries . Building a Simple Mobile App with Phone Gap Build Accelerometer Object and Methods Accelerometer Object and Methods Accelerometer Object and Methods Compass Object and Methods

PhoneGap's Compass API offers methods using which you can develop mobile apps that use compass. You can use the getCurrentHeading method of compass object to get the direction that the device is pointing at a specific point of time. If you want to get the direction information over a period of time, then you can use the watchHeading method and then clear the watch using watchHeading method once you are done. The magneticHeading property returns the heading in degrees. Compass Object and Methods

Available methods . compass.getCurrentHeading - The compass is a sensor that detects the direction or heading that the device is pointed, typically from the top of the device. It measures the heading in degrees from 0 to 359.99, where 0 is north.The compass heading information is returned via a CompassHeading object using the compassSuccess callback function. . compass.watchHeading - The compass is a sensor that detects the direction or heading that the device is pointed. It measures the heading in degrees from 0 to 359.99. The compass.watchHeading gets the device's current heading at a regular interval. Each time the heading is retrieved, the headingSuccess callback function is executed. Specify the interval in milliseconds via the frequency parameter in the compassOptions object. The returned watch ID references the compass watch interval. The watch ID can be used with compass.clearWatch to stop watching the compass. Geolocation Object and Methods

. cordova-plugin-geolocation . This plugin provides information about the device's location, such as latitude and longitude. . Common sources of location information include Global Positioning System (GPS) and location inferred from network signals such as IP address, RFID, WiFi and MAC addresses, and GSM/CDMA cell IDs. There is no guarantee that the API returns the device's actual location. . This API is based on the W3C Geolocation API Specification, and only executes on devices that don't already provide an implementation. Media Object and Methods

cordova-plugin-media . This plugin provides the ability to record and play back audio files on a device. The current implementation does not adhere to a W3C specification for media capture, and is provided for convenience only. A future implementation will adhere to the latest W3C specification and may deprecate the current APIs. . This plugin defines a global Media Constructor. Although in the global scope, it is not available until after the deviceready event. Camera Object and Methods

cordova-plugin-camera . This plugin defines a global navigator.camera object, which provides an API for taking pictures and for choosing images from the system's image library. . Although the object is attached to the global scoped navigator, it is not available until after the deviceready event. . Methods - . .getPicture(successCallback, errorCallback, options) . .cleanup() . .onError : function . .onSuccess : function . .CameraOptions : Object Storage Object and Methods

. Several storage APIs are available for Cordova applications. . Each API offers advantages and disadvantages, which are summarized here. You should choose whichever best suits your needs. You can also use several different approaches within a single application for different purposes. . LocalStorage - Local storage provides simple, synchronous key/value pair storage, and is supported by the underlying WebView implementations on all Cordova platforms. . WebSQL- WebSQL provides an API for storing data in a structured database that can be queried using a standard SQL syntax (specifically, SQLite). As such, it provides all the power (and complexity) of SQL. . IndexedDB - The goal of the IndexedDB API is to combine the strengths of the LocalStorage and WebSQL APIs, while avoiding their weaknesses. IndexedDB lets you store arbitrary JavaScript objects (provided they are supported by the structured clone algorithm), indexed with a key. It provides some of the benefits of SQL tables, without constraining the structure or needing to define it up front. IndexedDB provides a simple and easy to understand data model, much like LocalStorage. But unlike LocalStorage, you can create multiple databases, with multiple stores per database, and its asynchronous API and search indexes provide performance benefits. Files Object and Methods

cordova-plugin-file . This plugin implements a File API allowing read/write access to files residing on the device.

. This plugin is based on several specs, including : The HTML5 File API http://www.w3.org/TR/FileAPI/

. The Directories and System extensions Latest: http://www.w3.org/TR/2012/WD-file- system-api-20120417/ Although most of the plugin code was written when an earlier spec was current: http://www.w3.org/TR/2011/WD-file-system-api-20110419/ Contacts Object and Methods

cordova-plugin-contacts . This plugin defines a global navigator.contacts object, which provides access to the device contacts database. . Although the object is attached to the global scoped navigator, it is not available until after the deviceready event.

Methods – . navigator.contacts.create . navigator.contacts.find . navigator.contacts.pickContact Demos

. Your instructor will show you demos for all of the above APIs Looking Forward

In next session we will cover Packaging and Delivering a Cross-Platform App. We will briefly discuss – . Provisioning . Certificates . Packaging the App . Icons, splash screen and app configuration . Configuring meta tags for proper viewing Thank You.

By High School Technology Services myhsts.org