Book Image

Phonegap Essentials

By : Ivan Turkovic
Book Image

Phonegap Essentials

By: Ivan Turkovic

Overview of this book

Table of Contents (15 chapters)

Camera


The Camera plugin is one of the most useful features available through PhoneGap as it can access native UI components to take photos or select photos from the image library. Photos are present in many applications—for example, they can be used as profile pictures. This is one of the most used plugins for PhoneGap.

To install the plugin, you need to run the following command:

phonegap plugin add cordova-plugin-camera

The Camera plugin defines a global navigator.camera object, which provides an API for taking pictures and for choosing images from the system's image library. The object is available only after the deviceready event has been fired:

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    console.log(navigator.camera);
}

The Camera plugin has the following method:

  • navigator.camera.getPicture

The received image data can be displayed inside the application, saved to the application file directories, or used to send the image to the server...