--- title: Camera description: Take pictures with the device camera. --- # cordova-plugin-camera [![npm - Latest](https://img.shields.io/npm/v/cordova-plugin-camera/latest?label=Latest%20Release%20(npm))](https://npmjs.com/package/cordova-plugin-camera) [![GitHub](https://img.shields.io/github/package-json/v/apache/cordova-plugin-camera?label=Development%20(Git))](https://github.com/apache/cordova-plugin-camera) [![GitHub - Android Workflow](https://github.com/apache/cordova-plugin-camera/actions/workflows/android.yml/badge.svg?branch=master)](https://github.com/apache/cordova-plugin-camera/actions/workflows/android.yml?query=branch%3Amaster) [![GitHub - Chrome Workflow](https://github.com/apache/cordova-plugin-camera/actions/workflows/chrome.yml/badge.svg?branch=master)](https://github.com/apache/cordova-plugin-camera/actions/workflows/chrome.yml?query=branch%3Amaster) [![GitHub - iOS Workflow](https://github.com/apache/cordova-plugin-camera/actions/workflows/ios.yml/badge.svg?branch=master)](https://github.com/apache/cordova-plugin-camera/actions/workflows/ios.yml?query=branch%3Amaster) [![GitHub - Lint](https://github.com/apache/cordova-plugin-camera/actions/workflows/lint.yml/badge.svg?branch=master)](https://github.com/apache/cordova-plugin-camera/actions/workflows/lint.yml?query=branch%3Amaster) [![GitHub - Release Audit Workflow](https://github.com/apache/cordova-plugin-camera/actions/workflows/release-audit.yml/badge.svg?branch=master)](https://github.com/apache/cordova-plugin-camera/actions/workflows/release-audit.yml?query=branch%3Amaster) > [!NOTE] > Depending on your use case, this plugin may be unnecessary. > > We strongly recommend using the WebView's native `` element before opting for this plugin. > > The example above demonstrates how to capture an image. If you only need to select an existing image, simply remove the `capture` attribute. > > For more information: > > - [MDN – HTML element: ``](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input/file) > - [MDN – HTML attribute: `accept`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/accept) > - [MDN – HTML attribute: `capture`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/capture) > > For advanced use cases, this plugin may be appropriate. This plugin defines a global `navigator.camera` object, which provides an API for taking pictures and choosing images from the device's image library. Although the object is attached to the global `navigator` object, it is not available until after the `deviceready` event. ```js document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { console.log(navigator.camera); } ``` ## Supported Platforms - Android - Browser - iOS ## Installation ```bash cordova plugin add cordova-plugin-camera ``` ### Plugin Variables Plugin variables let you configure parts of a plugin and must be set during installation. To set these variables, append `--variable {VARIABLE_NAME}={VALUE}` to the `cordova plugin add` command for each variable. If you wish you change or remove any of the plugin variables, uninstall and reinstall with the updated variables. - **`ANDROIDX_CORE_VERSION`** **Default:** `1.6.+` This variable allows you to configure the `androidx.core:core` dependency for this plugin only. Some plugins may include this dependency with hard-coded versions, so you can use this variable to try to match those versions and reduce conflicts. **Example:** ```bash cordova plugin add cordova-plugin-camera --variable ANDROIDX_CORE_VERSION=1.8.0 ``` ## App Configuration The following preferences can be set in the app's `config.xml` file to configure the plugin. ### Android-Specific #### Supporting `saveToPhotoAlbum` on Android 9 (API 28) & Lower > [!WARNING] > If you support Android 9 (API 28) and lower and need `saveToPhotoAlbum`, then this step is required. > > If you support only Android 10 (API 29) and later, or do not need `saveToPhotoAlbum`, then skip this step. > > Configuring the `WRITE_EXTERNAL_STORAGE` permission for Android 10 or later has no effect. To declare the `WRITE_EXTERNAL_STORAGE` permission, add the following: ```xml ``` ### iOS-Specific #### Mandatory Usage Description > [!WARNING] > Since iOS 10, you must provide usage descriptions in the `info.plist` when accessing privacy-sensitive data. The required keys depend on how you use the plugin and which iOS versions you support: | Key | Description | | ------------------------------ | ----------- | | NSCameraUsageDescription | Required whenever the camera is used (e.g. `Camera.PictureSourceType.CAMERA`). | | NSPhotoLibraryUsageDescription | Required only when your app runs on iOS 13 or older and using as `sourceType` `Camera.PictureSourceType.PHOTOLIBRARY`. On iOS 14+ the plugin uses PHPicker for read-only access, which does not need this key. | | NSPhotoLibraryAddUsageDescription | Required when the plugin writes to the user's library (e.g. `saveToPhotoAlbum=true`). | | NSLocationWhenInUseUsageDescription | Required if `CameraUsesGeolocation` is set to `true`. | When the system prompts the user to allow access, this usage description string will be displayed as part of the permission dialog box. If you don't provide the required usage description, the app will crash before showing the dialog. Also, Apple will reject apps that access private data but don't provide a usage description. To add these entries into the `info.plist`, you can use the `edit-config` tag in the `config.xml` like this: ```xml need camera access to take pictures need photo library access to get pictures from there need photo library access to save pictures there need location access to find things nearby ``` #### Preferences - **`CameraUsesGeolocation`** **Default:** `false` (boolean) Enables geolocation data in the EXIF header when capturing JPEG images. When set to `true`, the app will request for geolocation permissions . To set this preference, add the following: ```xml ``` --- # API Reference - [camera](#module_camera) - [.getPicture(successCallback, errorCallback, options)](#module_camera.getPicture) - [.cleanup()](#module_camera.cleanup) - [.onError](#module_camera.onError) : function - [.onSuccess](#module_camera.onSuccess) : function - [.CameraOptions](#module_camera.CameraOptions) : Object - [Camera](#module_Camera) - [.DestinationType](#module_Camera.DestinationType) : enum - [.EncodingType](#module_Camera.EncodingType) : enum - [.MediaType](#module_Camera.MediaType) : enum - [.PictureSourceType](#module_Camera.PictureSourceType) : enum - [.Direction](#module_Camera.Direction) : enum --- ## camera ### camera.getPicture(successCallback, errorCallback, options) Takes a photo using the camera, or retrieves a photo from the device's image gallery. The result is provided in the first parameter of the `successCallback` as a string. As of v8.0.0, the result is formatted as URIs. The scheme will vary depending on settings and platform. |Platform|Destination Type|Format| |---|---|---| |Android|FILE_URI|An URI scheme such as `file://...` or `content://...`| ||DATA_URL|Base 64 encoded with the proper data URI header| |iOS|FILE_URI|`file://` schemed paths| ||DATA_URL|Base 64 encoded with the proper data URI header| |Browser|FILE_URI|Not supported| ||DATA_URL|Base 64 encoded with the proper data URI header| v7 and earlier versions, the return format is as follows: |Platform|Destination Type|Format| |---|---|---| |Android|FILE_URI|Raw file path (unprefixed)| ||DATA_URL|Base 64 encoded, without the `data:` prefix |iOS|FILE_URI|`file://` schemed paths| ||DATA_URL|Base 64 encoded, without the `data:` prefix |Browser|FILE_URI|Not supported| ||DATA_URL|Base 64 encoded, without the `data:` prefix| For this reason, upgrading to v8 is strongly recommended as it greatly streamlines the return data. 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 [`Camera.PictureSourceType.CAMERA`](#module_Camera.PictureSourceType). Once the user snaps the photo, the camera application closes and the application is restored. If `Camera.sourceType` is `Camera.PictureSourceType.PHOTOLIBRARY` or `Camera.PictureSourceType.SAVEDPHOTOALBUM`, then a dialog displays that allows users to select an existing image. The return value is sent to the [`cameraSuccess`](#module_camera.onSuccess) callback function, in one of the following formats, depending on the specified `cameraOptions`. You can do whatever you want with content: - Render the content in an `` or `