Book Image

JavaScript Mobile Application Development

Book Image

JavaScript Mobile Application Development

Overview of this book

Table of Contents (15 chapters)
JavaScript Mobile Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Overview of Cordova APIs


Currently, Apache Cordova supports the following mobile native functions APIs:

  • Accelerometer: This allows you to capture the device motion in all directions (x, y, and z)

  • Camera: This allows you to use the default camera application in order to capture photos

  • Capture: This allows you to capture audio using the device's audio recording application, capture images using the device's camera application, and capture video using the device's video recording application

  • Compass: This allows you to get the direction that the device is pointing to

  • Connection: This provides you with the information about the device's cellular and Wi-Fi connection

  • Contacts: This allows you to access the device's contacts database, create new contacts in the contacts list, and query the existing device contacts list

  • Device: This allows you to get the hardware and software information of the device; for example, it allows you to get the device model, receive the platform and its version, and finally, receive the device name

  • Events: This allows you to listen and create handlers for Apache Cordova life cycle events. These life cycle events are as follows:

    • deviceready: This event fires once Apache Cordova is fully loaded

    • pause: This event fires if the application is put into the background

    • resume: This event fires if the application is resumed from the background

    • online: This event fires if the application becomes connected to the Internet

    • offline: This event fires if the application becomes disconnected from the Internet

    • backbutton: This event fires if the user clicks the device's back button (some mobile devices have a back button, such as Android and Windows Phone devices)

    • batterycritical: This event fires if the device's battery power reaches a critical state (that is, reaches the critical-level threshold)

    • batterylow: This event fires if the device battery power reaches the low-level threshold

    • batterystatus: This event fires if there is a change in the battery status

    • menubutton: This event fires if the user presses the device's menu button (the menu button is popular for Android and BlackBerry devices)

    • searchbutton: This event fires if the user presses the device's search button (the search button can be found in Android devices)

    • startcallbutton: This event fires when the user presses the start and end call buttons of the device

    • endcallbutton: This event fires when the user presses the start and end call buttons of the device

    • volumeupbutton: This event fires when the user presses the volume up and down buttons of the device

    • volumedownbutton: This event fires when the user presses the volume up and down buttons of the device

  • File: This allows you to process files (which is to read, write, and navigate filesystem directories), and it is based on the W3C file APIs

  • Geolocation: This allows you to receive the device's location using GPS or using network signals, and it is based on W3C geolocation APIs

  • Globalization: This allows you to get the user's locale and perform locale-specific operations

  • InAppBrowser: This represents a web browser view that is displayed when any call to window.open() or a link whose target is set to "_blank" is clicked

  • Media: This allows for the recording of audio files programmatically, without using the device default recording application, as well as playing audio files

  • Notification: This allows the display of audible notifications such as beeps, the display of tactile notifications such as vibrations, and displaying visual notifications such as the normal device visual messages to the user

  • Splashscreen: This allows you to display application splash screen

  • Storage: Apache Cordova provides the following storage capabilities:

    • Using the W3C web storage interface which is about LocalStorage and SessionStorage. It is important to know that local storage is a permanent storage that exists on your device even if your application is closed, while session storage is a temporary storage that is erased when the user session ends, which is when the application is closed.

    • Using the full features of relational databases by supporting Web SQL on almost all the platforms. For Windows Phone and Windows Platform, it supports IndexedDB, which is currently a W3C standard.

Tip

Although Web SQL is deprecated, it was and still is a powerful specification for creating and working with relational data.

All of these APIs will be illustrated in far more detail, along with examples, as you read this book. It is important to note that not all of these APIs are supported in all the platforms. You will be able to specifically check which ones are not supported in the following list. Also note that this list applies to Apache Cordova Version 3.4, and it might be changed later. The following table shows the unsupported APIs on the different platforms. Please note that X here means unsupported:

 

Firefox OS

Tizen

Windows 8

Blackberry 10

Capture API

X

X

X

 

Compass

X

   

Connection

X

   

Contacts

 

X

X

 

Events

X

   

File

X

X

  

Globalization

X

X

X

X

InAppBrowser

X

X

  

Media

X

   

Notification

X

   

Splashscreen

X

X

  

Storage

X