Monaca Docs
  • Monaca
  • Create Your First App
  • Release Notes and Updates
    • Privacy Manifest Requirement for iOS Apps
    • Plugin uses-permission Tag Deduplication Feature
    • iOS Monaca Debugger Discontinuation & Alternative Features
    • Error submitting to iOS App Store (ITMS-90165)
    • Build error in cordova-custom-config
    • Cordova 11 changes
    • Cordova 10 changes
    • Cordova 9 changes
    • New Monaca CLI and Localkit
    • Migration from Cordova to Capacitor
  • Product Guides
    • Monaca Development Overview
    • Monaca Cloud IDE
      • Overview
      • Features in the Monaca Cloud IDE
      • Integrated Terminal
      • Editor Shortcuts
      • Project Dependencies
        • File and Folder Structure
        • JS/CSS Components
        • Cordova Plugins
        • Custom Cordova Plugins
      • Version Control
        • Introduction
        • GitHub Integration
        • Git SSH Integration
      • Monaca CI
        • Overview
        • Deploy Services
        • Deploy to Appetize.io
        • Deploy to DeployGate
        • Deploy to Firebase
      • Build
        • Building for iOS
          • Building an iOS App
          • Build Settings between Monaca and Xcode
        • Building for Android
        • Building for Electron
          • Building on Windows
        • Building for PWA
        • Building for Windows
        • Build Environment Settings
        • Common Build and Application Upload Errors
        • Build History
      • Distribution
        • App Store Distribution
          • App Store Connect Guide
          • iOS App Upload Feature
        • Google Play Distribution
        • Amazon Appstore Distribution
        • Non-market App Distribution
      • Download App Package
      • Tutorial
    • Monaca Localkit
      • Overview
      • Pairing and Debugging
      • Remote Building and Publishing
      • Troubleshooting Guide
      • Tutorial
    • Monaca CLI
      • Overview
      • Monaca CLI Commands
      • Pairing and Debugging
      • Project Dependencies
        • File and Folder Structure
        • JS/JSS Components
        • Cordova Plugins
        • Custom Cordova Plugins
      • Remote Building and Publishing
      • Troubleshooting Guide
      • Tutorial
    • Monaca Debugger
      • Functionalities
      • Installation
        • Monaca Debugger for Android
        • Monaca Debugger for iOS
        • Monaca Debugger for Android Emulator
      • Usage
      • Custom Build Debugger for iOS
      • iOS App Simulator Build
      • Troubleshooting Guide
      • Tutorials
    • Team Dashboard
    • Quick Viewer
    • Migrating from Other Platforms
      • Key Points
      • Cloud IDE preview function settings
      • Migrating from Angular
      • Migrating from Ionic
      • Migrating from React
      • Migrating from Vue
      • Migrating from PhoneGap
        • Key Differences
        • Guide for PhoneGap Build Users
        • Guide for PhoneGap CLI Users
        • Guide for PhoneGap Desktop App Users
      • Migrating from Telerik
  • Build App
    • Build for iOS
      • Creating a Private Key and CSR
      • Creating a Certificate
      • Updating Provisioning Profiles
  • Tutorials
    • Monaca Cloud IDE Tutorial
      • Part 1: Starting a Project
      • Part 2: Running Monaca Debugger with Monaca Cloud IDE
      • Part 3: Building a Monaca App
      • Part 4: Publishing a Monaca App
    • Monaca Localkit Tutorial
      • Part 1: Starting a Project
      • Part 2: Running Monaca Debugger with Monaca Localkit
      • Part 3: Building a Monaca App
      • Part 4: Publishing a Monaca App
    • Monaca CLI Tutorial
      • Part 1: Starting a Project
      • Part 2: Running Monaca Debugger with Monaca CLI
      • Part 3: Building a Monaca App
      • Part 4: Publishing a Monaca App
    • Electron Tutorial
      • How to Use a NPM Package
      • How to Use a Web API
    • Barcode Scanner Plugin
    • Cordova SQLite Storage Plugin
    • Cordova Google Analytics Plugin
    • Cordova Firebase Plugin
    • Cordova In-app Purchase Plugin
    • Cordova AppVersion Plugin
    • Cordova Ionic Keyboard Plugin
    • Cordova Social Sharing Plugin
    • NIFCLOUD mobile backend
    • Phonegap Push Plugin
  • API Reference
    • Monaca API
      • Monaca Cloud & Remote Build API Guide
      • Utilities
    • Core Cordova Plugins
      • Cordova 11.0
        • Battery Status Plugin
        • Camera Plugin
        • Device Plugin
        • Device Motion Plugin
        • Device Orientation Plugin
        • Dialogs Plugin
        • File Plugin
        • Geolocation Plugin
        • InAppBrowser Plugin
        • Media Plugin
        • Media Capture Plugin
        • Network Information Plugin
        • Splashscreen Plugin
        • Vibration Plugin
        • StatusBar Plugin
      • Cordova 10.0
        • Battery Status Plugin
        • Camera Plugin
        • Device Plugin
        • Device Motion Plugin
        • Device Orientation Plugin
        • Dialogs Plugin
        • File Plugin
        • Geolocation Plugin
        • InAppBrowser Plugin
        • Media Plugin
        • Media Capture Plugin
        • Network Information Plugin
        • Splashscreen Plugin
        • Vibration Plugin
        • StatusBar Plugin
        • Whitelist Plugin (Android Only)
      • Cordova 9.0
        • Battery Status Plugin
        • Camera Plugin
        • Contacts Plugin
        • Device Plugin
        • Device Motion Plugin
        • Device Orientation Plugin
        • Dialogs Plugin
        • File Plugin
        • File Transfer Plugin
        • Geolocation Plugin
        • Globalization Plugin
        • InAppBrowser Plugin
        • Media Plugin
        • Media Capture Plugin
        • Network Information Plugin
        • Splashscreen Plugin
        • Vibration Plugin
        • StatusBar Plugin
        • Whitelist Plugin (Android Only)
    • Third-party Cordova Plugins
      • Advanced HTTP Plugin
      • PhoneGap BarcodeScanner Plugin
      • Cordova Custom Config Plugin
      • DatePicker Plugin
      • Share Plugin (Android)
      • WebIntent Plugin (Android)
    • Monaca Power Plugins
      • Monaca HTML5 Resource Encryption
      • Monaca In-App Updater
      • Monaca Secure Storage
      • Barcode Scanner Plugin
      • Android build memory size setting
    • Service Integration
      • Repro
      • AppsFlyer
    • Configuration Files
      • Android
        • Android Configuration
        • config.xml
        • AndroidManifest.xml
      • iOS
        • iOS Configuration
        • config.xml
        • MonacaApp-Info.plist
  • Samples & Tips
    • Sample Apps
      • AdMob
      • Twitter Single Sign-on App
      • Facebook Single Sign-on App
      • Flickr
      • TODO App
      • BirthYear App
      • Break the Bricks
      • Train Catalog App
      • Omikuji Fortune Telling App
      • Clock App
      • Memo Application
      • RSS Reader App
      • Hello World App
    • Tips & Tricks
      • Playing Sound and Music
      • Control the Splash Screen
      • Using Database
  • Features
    • Push Notification
    • SNS Authentication
    • Database
  • FAQ
    • General
    • IDE
    • Build
    • Release
    • Subscription
      • How to Use Activation Code
    • Application
    • Usage
    • Debugger
  • Supported Environments
  • Trouble Shooting
    • Preview Log repeats to reload (Vue packages version mismatch error)
  • Monaca Product Website
  • 日本語
Powered by GitBook
On this page
  • Plugin ID
  • Adding the Plugin in Monaca
  • iOS Quirks
  • API Reference
  • camera
  • Camera
  • CameraPopoverOptions
  • CameraPopoverHandle
  • camera.getPicture Errata
  • CameraOptions Errata
  • Samples
  • Take a Picture
  • Take a Picture and Return Thumbnails (Resize the Picture)
  • Select a File from the Picture Library
  • Select an Image and Return Thumbnails (resized images)
  • Take a picture and get a FileEntry Object

Was this helpful?

  1. API Reference
  2. Core Cordova Plugins
  3. Cordova 9.0

Camera Plugin

PreviousBattery Status PluginNextContacts Plugin

Last updated 3 years ago

Was this helpful?

Tested Version:

This document is based on the original Cordova docs available at .

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.

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

Plugin ID

cordova-plugin-camera

Adding the Plugin in Monaca

In order to use this plugin, please Camera plugin in Monaca Cloud IDE.

iOS Quirks

Since iOS 10 it's mandatory to provide usage description in the info.plist if trying to access privacy-sensitive data. When the system prompts the user to allow access, this usage description string will displayed as part of the permission dialog box, but if you didn't provide the usage description, the app will crash before showing the dialog. Also, Apple will reject apps that access private data but don't provide usage description.

This plugins requires the following usage descriptions:

  • NSCameraUsageDescription specifies the reason for your app to access the device's camera.

  • NSPhotoLibraryUsageDescription specifies the reason for your app to access the user's photo library.

  • NSLocationWhenInUseUsageDescription specifies the reason for your app to access the user's location information while your app is in use. (Set it if you have CameraUsesGeolocation preference set to true)

  • NSPhotoLibraryAddUsageDescription specifies the reason for your app to get write-only access to the user's photo library

To add these entries into the info.plist, you can use the <edit-config> tag in the config.xml file like this:

<edit-config target="NSCameraUsageDescription" file="*-Info.plist" mode="merge">
    <string>need camera access to take pictures</string>
</edit-config>

<edit-config target="NSPhotoLibraryUsageDescription" file="*-Info.plist" mode="merge">
    <string>need to photo library access to get pictures from there</string>
</edit-config>

<edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
    <string>need location access to find things nearby</string>
</edit-config>

<edit-config target="NSPhotoLibraryAddUsageDescription" file="*-Info.plist" mode="merge">
    <string>need to photo library access to save pictures there</string>
</edit-config>

API Reference

camera

camera.getPicture(successCallback, errorCallback, options)

Takes a photo using the camera, or retrieves a photo from the device's image gallery. The image is passed to the success callback as a Base64-encoded String, or as the URI for the image file.

If Camera.sourceType is Camera.PictureSourceType.PHOTOLIBRARY or Camera.PictureSourceType.SAVEDPHOTOALBUM, then a dialog displays that allows users to select an existing image.

  • A String containing the Base64-encoded photo image.

  • A String representing the image file location on local storage

    (default).

You can do whatever you want with the encoded image or URI, for example:

  • Render the image in an <img> tag, as in the example below

  • Post the data to a remote server

Photo resolution on newer devices is quite good. Photos selected from the device's gallery are not downscaled to a lower quality, even if a quality parameter is specified. To avoid common memory problems, set Camera.destinationType to FILE_URI rather than DATA_URL.

Supported Platforms

  • Android

  • iOS

Param

Type

Description

successCallback

Function

errorCallback

Function

options

JSON Object

Example

navigator.camera.getPicture(cameraSuccess, cameraError, cameraOptions);

camera.cleanup()

Supported Platforms

  • iOS

Example

navigator.camera.cleanup(onSuccess, onFail);

function onSuccess() {
    console.log("Camera cleanup success.")
}

function onFail(message) {
    alert('Failed because: ' + message);
}

camera.onError : function

Callback function that provides an error message.

Param

Type

Description

message

String

The message is provided by the device's native code

camera.onSuccess : function

Callback function that provides the image data.

Param

Type

Description

imageData

String

Example

// Show image
//
function cameraCallback(imageData) {
   var image = document.getElementById('myImage');
   image.src = "data:image/jpeg;base64," + imageData;
}

camera.CameraOptions : Object

Optional parameters to customize the camera settings.

Properties

Name

Type

Default

Description

quality

Number

50

Quality of the saved image, expressed as a range of 0-100, where 100 is typically full resolution with no loss from file compression. (Note that information about the camera’s resolution is unavailable.)

destinationType

FILE_URI

Choose the format of the return value.

sourceType

CAMERA

Set the source of the picture.

allowEdit

Boolean

true

Allow simple editing of image before selection.

encodingType

JPEG

Choose the returned image file’s encoding.

targetWidth

Number

Width in pixels to scale image. Must be used with targetHeight. Aspect ratio remains constant.

targetHeight

Number

Height in pixels to scale image. Must be used with targetWidth. Aspect ratio remains constant.

mediaType

PICTURE

Set the type of media to select from. Only works when PictureSourceType is PHOTOLIBRARY or SAVEDPHOTOALBUM.

correctOrientation

Boolean

Rotate the image to correct for the orientation of the device during capture.

saveToPhotoAlbum

Boolean

Save the image to the photo album on the device after capture.

popoverOptions

iOS-only options that specify popover location in iPad.

cameraDirection

BACK

Choose the camera to use (front- or back-facing).

Camera

Camera.DestinationType : enum

Defines the output format of Camera.getPicture call.

On iOSpassing DestinationType.NATIVE_URI along with PictureSourceType.PHOTOLIBRARY or PictureSourceType.SAVEDPHOTOALBUM will disable any image modifications (resize, quality change, cropping, etc.) due to implementation specific.

Properties

Name

Type

Default

Description

DATA_URL

Number

0

Return base64 encoded string. DATA_URL can be very memory intensive and cause app crashes or out of memory errors. Use FILE_URI or NATIVE_URI if possible

FILE_URI

Number

1

Return file uri (content://media/external/images/media/2 for Android)

NATIVE_URI

Number

2

Return native uri (eg. asset-library://... for iOS)

Camera.EncodingType : enum

Properties

Name

Type

Default

Description

JPEG

Number

0

Return JPEG encoded image

PNG

Number

1

Return PNG encoded image

Camera.MediaType : enum

Properties

Name

Type

Default

Description

PICTURE

Number

0

Allow selection of still pictures only. DEFAULT. Will return format specified via DestinationType

VIDEO

Number

1

Allow selection of video only, ONLY RETURNS URL

ALLMEDIA

Number

2

Allow selection from all media types

Camera.PictureSourceType : enum

Defines the output format of Camera.getPicture call.

On iOS passing PictureSourceType.PHOTOLIBRARY or PictureSourceType.SAVEDPHOTOALBUM along with DestinationType.NATIVE_URI will disable any image modifications (resize, quality change, cropping, etc.) due to implementation specific.

Properties

Name

Type

Default

Description

PHOTOLIBRARY

Number

0

Choose image from the device’s photo library (same as SAVEDPHOTOALBUM for Android)

CAMERA

Number

1

Take picture from camera

SAVEDPHOTOALBUM

Number

2

Choose image only from the device’s Camera Roll album (same as PHOTOLIBRARY for Android)

Camera.PopoverArrowDirection : enum

Matches iOS UIPopoverArrowDirection constants to specify arrow location on popover.

Name

Type

Default

ARROW_UP

Number

1

ARROW_DOWN

Number

2

ARROW_LEFT

Number

4

ARROW_RIGHT

Number

8

ARROW_ANY

Number

15

Camera.Direction : enum

Properties

Name

Type

Default

Description

BACK

Number

0

Use the back-facing camera

FRONT

Number

1

Use the front-facing camera

CameraPopoverOptions

iOS-only parameters that specify the anchor element location and arrow direction of the popover when selecting images from an iPad's library or album. Note that the size of the popover may change to adjust to the direction of the arrow and orientation of the screen. Make sure to account for orientation changes when specifying the anchor element location.

Name

Type

Default

Description

[x]

Number

0

x pixel coordinate of screen element onto which to anchor the popover.

[y]

Number

32

y pixel coordinate of screen element onto which to anchor the popover.

[width]

Number

320

width, in pixels, of the screen element onto which to anchor the popover.

[height]

Number

480

height, in pixels, of the screen element onto which to anchor the popover.

[arrowDir]

ARROW_ANY

Direction the arrow on the popover should point.

CameraPopoverHandle

A handle to an image picker popover.

Supported Platforms

  • iOS

Example

navigator.camera.getPicture(onSuccess, onFail,
{
    destinationType: Camera.DestinationType.FILE_URI,
    sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
    popoverOptions: new CameraPopoverOptions(300, 300, 100, 100, Camera.PopoverArrowDirection.ARROW_ANY)
});

// Reposition the popover if the orientation changes.
window.onorientationchange = function() {
    var cameraPopoverHandle = new CameraPopoverHandle();
    var cameraPopoverOptions = new CameraPopoverOptions(0, 0, 100, 100, Camera.PopoverArrowDirection.ARROW_ANY);
    cameraPopoverHandle.setPosition(cameraPopoverOptions);
}

camera.getPicture Errata

Example

Take a photo and retrieve the image's file location:

navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
    destinationType: Camera.DestinationType.FILE_URI });

function onSuccess(imageURI) {
    var image = document.getElementById('myImage');
    image.src = imageURI;
}

function onFail(message) {
    alert('Failed because: ' + message);
}

Take a photo and retrieve it as a Base64-encoded image:

/**
 * Warning: Using DATA_URL is not recommended! The DATA_URL destination
 * type is very memory intensive, even with a low quality setting. Using it
 * can result in out of memory errors and application crashes. Use FILE_URI
 * or NATIVE_URI instead.
 */
navigator.camera.getPicture(onSuccess, onFail, { quality: 25,
    destinationType: Camera.DestinationType.DATA_URL
});

function onSuccess(imageData) {
    var image = document.getElementById('myImage');
    image.src = "data:image/jpeg;base64," + imageData;
}

function onFail(message) {
    alert('Failed because: ' + message);
}

Preferences (iOS)

CameraUsesGeolocation (boolean, defaults to false). For capturing JPEGs, set to true to get geolocation data in the EXIF header. This will trigger a request for geolocation permissions if set to true.

xml<preference name="CameraUsesGeolocation" value="false" />

Android Quirks

iOS Quirks

Including a JavaScript alert() in either of the callback functions can cause problems. Wrap the alert within a setTimeout() to allow the iOS image picker or popover to fully close before the alert displays:

setTimeout(function() {
    // do your thing here!
}, 0);

CameraOptions Errata

Android Quirks

  • Any cameraDirection value results in a back-facing photo.

  • allowEdit is unpredictable on Android and it should not be used! The Android implementation of this plugin tries to find and use an application on the user's device to do image cropping. The plugin has no control over what application the user selects to perform the image cropping and it is very possible that the user could choose an incompatible option and cause the plugin to fail. This sometimes works because most devices come with an application that handles cropping in a way that is compatible with this plugin (Google Plus Photos), but it is unwise to rely on that being the case. If image editing is essential to your application, consider seeking a third party library or plugin that provides its own image editing utility for a more robust solution.

  • Camera.PictureSourceType.PHOTOLIBRARY and Camera.PictureSourceType.SAVEDPHOTOALBUM both display the same photo album.

  • Ignores the encodingType parameter if the image is unedited (i.e. quality is 100, correctOrientation is false, and no targetHeight or targetWidth are specified). The CAMERA source will always return the JPEG file given by the native camera and the PHOTOLIBRARY and SAVEDPHOTOALBUM sources will return the selected file in its existing encoding.

iOS Quirks

  • When using destinationType.FILE_URI, photos are saved in the application's temporary directory. The contents of the application's temporary directory is deleted when the application ends.

  • When using destinationType.NATIVE_URI and sourceType.CAMERA, photos are saved in the saved photo album regardless on the value of saveToPhotoAlbum parameter.

  • When using destinationType.NATIVE_URI and sourceType.PHOTOLIBRARY or sourceType.SAVEDPHOTOALBUM, all editing options are ignored and link is returned to original picture.

Samples

The Camera plugin allows you to do things like open the device's Camera app and take a picture, or open the file picker and select one. The code snippets in this section demonstrate different tasks including:

Take a Picture

Before you can take a picture, you need to set some Camera plugin options to pass into the Camera plugin's getPicture function. Here is a common set of recommendations. In this example, you create the object that you will use for the Camera options, and set the sourceType dynamically to support both the Camera app and the file picker.

function setOptions(srcType) {
    var options = {
        // Some common settings are 20, 50, and 100
        quality: 50,
        destinationType: Camera.DestinationType.FILE_URI,
        // In this app, dynamically set the picture source, Camera or photo gallery
        sourceType: srcType,
        encodingType: Camera.EncodingType.JPEG,
        mediaType: Camera.MediaType.PICTURE,
        allowEdit: true,
        correctOrientation: true  //Corrects Android orientation quirks
    }
    return options;
}

Typically, you want to use a FILE_URI instead of a DATA_URL to avoid most memory issues. JPEG is the recommended encoding type for Android.

You take a picture by passing in the options object to getPicture, which takes a CameraOptions object as the third argument. When you call setOptions, pass Camera.PictureSourceType.CAMERA as the picture source.

function openCamera(selection) {

    var srcType = Camera.PictureSourceType.CAMERA;
    var options = setOptions(srcType);
    var func = createNewFileEntry;

    navigator.camera.getPicture(function cameraSuccess(imageUri) {

        displayImage(imageUri);
        // You may choose to copy the picture, save it somewhere, or upload.
        func(imageUri);

    }, function cameraError(error) {
        console.debug("Unable to obtain picture: " + error, "app");

    }, options);
}

Once you take the picture, you can display it or do something else. In this example, call the app's displayImage function from the preceding code.

function displayImage(imgUri) {

    var elem = document.getElementById('imageFile');
    elem.src = imgUri;
}

To display the image on some platforms, you might need to include the main part of the URI in the Content-Security-Policy <meta> element in index.html. Here is an example.

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: ms-appdata: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">

Take a Picture and Return Thumbnails (Resize the Picture)

To get smaller images, you can return a resized image by passing both targetHeight and targetWidth values with your CameraOptions object. In this example, you resize the returned image to fit in a 100px by 100px box (the aspect ratio is maintained, so 100px is either the height or width, whichever is greater in the source).

function openCamera(selection) {

    var srcType = Camera.PictureSourceType.CAMERA;
    var options = setOptions(srcType);
    var func = createNewFileEntry;

    if (selection == "camera-thmb") {
        options.targetHeight = 100;
        options.targetWidth = 100;
    }

    navigator.camera.getPicture(function cameraSuccess(imageUri) {

        // Do something

    }, function cameraError(error) {
        console.debug("Unable to obtain picture: " + error, "app");

    }, options);
}

Select a File from the Picture Library

When selecting a file using the file picker, you also need to set the CameraOptions object. In this example, set the sourceType to Camera.PictureSourceType.SAVEDPHOTOALBUM. To open the file picker, call getPicture just as you did in the previous example, passing in the success and error callbacks along with CameraOptions object.

function openFilePicker(selection) {

    var srcType = Camera.PictureSourceType.SAVEDPHOTOALBUM;
    var options = setOptions(srcType);
    var func = createNewFileEntry;

    navigator.camera.getPicture(function cameraSuccess(imageUri) {

        // Do something

    }, function cameraError(error) {
        console.debug("Unable to obtain picture: " + error, "app");

    }, options);
}

Select an Image and Return Thumbnails (resized images)

Resizing a file selected with the file picker works just like resizing using the Camera app; set the targetHeight and targetWidth options.

function openFilePicker(selection) {

    var srcType = Camera.PictureSourceType.SAVEDPHOTOALBUM;
    var options = setOptions(srcType);
    var func = createNewFileEntry;

    if (selection == "picker-thmb") {
        // To downscale a selected image,
        // Camera.EncodingType (e.g., JPEG) must match the selected image type.
        options.targetHeight = 100;
        options.targetWidth = 100;
    }

    navigator.camera.getPicture(function cameraSuccess(imageUri) {

        // Do something with image

    }, function cameraError(error) {
        console.debug("Unable to obtain picture: " + error, "app");

    }, options);
}

Take a picture and get a FileEntry Object

If you want to do something like copy the image to another location, or upload it somewhere using the FileTransfer plugin, you need to get a FileEntry object for the returned picture. To do that, call window.resolveLocalFileSystemURL on the file URI returned by the Camera app. If you need to use a FileEntry object, set the destinationType to Camera.DestinationType.FILE_URI in your CameraOptions object (this is also the default value).

Here is the call to window.resolveLocalFileSystemURL. The image URI is passed to this function from the success callback of getPicture. The success handler of resolveLocalFileSystemURL receives the FileEntry object.

function getFileEntry(imgUri) {
    window.resolveLocalFileSystemURL(imgUri, function success(fileEntry) {

        // Do something with the FileEntry object, like write to it, upload it, etc.
        // writeFile(fileEntry, imgUri);
        console.log("got file: " + fileEntry.fullPath);
        // displayFileData(fileEntry.nativeURL, "Native URL");

    }, function () {
      // If don't get the FileEntry (which may happen when testing
      // on some emulators), copy to a new FileEntry.
        createNewFileEntry(imgUri);
    });
}

In the example shown in the preceding code, you call the app's createNewFileEntry function if you don't get a valid FileEntry object. The image URI returned from the Camera app should result in a valid FileEntry, but platform behavior on some emulators may be different for files returned from the file picker.

The code shown here creates a file in your app's cache (in sandboxed storage) named tempFile.jpeg. With the new FileEntry object, you can copy the image to the file or do something else like upload it.

function createNewFileEntry(imgUri) {
    window.resolveLocalFileSystemURL(cordova.file.cacheDirectory, function success(dirEntry) {

        // JPEG file
        dirEntry.getFile("tempFile.jpeg", { create: true, exclusive: false }, function (fileEntry) {

            // Do something with it, like write to it, upload it, etc.
            // writeFile(fileEntry, imgUri);
            console.log("got file: " + fileEntry.fullPath);
            // displayFileData(fileEntry.fullPath, "File copied to");

        }, onErrorCreateFile);

    }, onErrorResolveUrl);
}

See Also:

: function

: function

: Object

: enum

: enum

: enum

: enum

: enum

: enum

The camera.getPicture function opens the device's default camera application that allows users to snap pictures by default - this behavior occurs, when Camera.sourceType equals . Once the user snaps the photo, the camera application closes and the application is restored.

The return value is sent to the callback function, in one of the following formats, depending on the specified cameraOptions:

Save the data locally (LocalStorage, , etc.)

More examples . Quirks .

Kind: static method of

Removes intermediate image files that are kept in temporary storage after calling . Applies only when the value of Camera.sourceType equals Camera.PictureSourceType.CAMERA and the Camera.destinationType equals Camera.DestinationType.FILE_URI.

Kind: static method of

Kind: static typedef of

Kind: static typedef of

Base64 encoding of the image data, or the image file URI, depending on in effect.

Kind: static typedef of

Kind: static enum property of

Kind: static enum property of

Kind: static enum property of

Kind: static enum property of

Kind: static enum property of Properties

Kind: static enum property of

Android uses intents to launch the camera activity on the device to capture images, and on phones with low memory, the Cordova activity may be killed. In this scenario, the result from the plugin call will be delivered via the resume event. See for more information. The pendingResult.result value will contain the value that would be passed to the callbacks (either the URI/URL or an error message). Check the pendingResult.pluginStatus to determine whether or not the call was successful.

Open the Camera app and

Take a picture and

Take a picture and

from the picture library

Select a JPEG image and

Select an image and

You need the to call window.resolveLocalFileSystemURL.

To see an example of writing to a FileEntry, see the .

Lawnchair
the Android Lifecycle guide
File plugin
File plugin README
Third-party Cordova Plugins
Core Cordova Plugins
camera
.getPicture(successCallback, errorCallback, options)
.cleanup()
.onError
.onSuccess
.CameraOptions
Camera
.DestinationType
.EncodingType
.MediaType
.PictureSourceType
.PopoverArrowDirection
.Direction
CameraPopoverHandle
CameraPopoverOptions
Camera.PictureSourceType.CAMERA
cameraSuccess
here
here
camera
camera.getPicture
camera
camera
camera
Quirks
camera
Camera
Camera
Camera
Camera
Camera
camera
take a Picture
return thumbnails (resized picture)
generate a FileEntry object
Select a file
return thumbnails (resized image)
generate a FileEntry object
onSuccess
onError
CameraOptions
cameraOptions
DestinationType
PictureSourceType
EncodingType
MediaType
CameraPopoverOptions
Direction
PopoverArrowDirection
4.0.3
Cordova Docs
enable