O'Reilly logo

PhoneGap Essentials by Ivan Turkovic

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required