Version: Smart Feature Phone 3.0

CameraManager.getCamera()

Description#

This method is used to access to one of the cameras available on the device based on its identifier. You can get a list of the available cameras by calling the CameraManager.getListOfCameras() method.


Syntax#

Promise CameraManager.getCamera(camera, cameraConfiguration);

Parameters#

camera

       Specify the camera you want to use (the device may have more than one camera).

cameraConfiguration

       An object allowing you to set camera options for this camera: mode, previewSize and recorderProfile.

Return Value#

       Returns a Promise. The Promise's .then() function accepts two function arguments:

onsuccess

       A callback function that take an object as parameter. This object has the camera property as CameraControl object and the configuration property as actual cameraConfiguration of device.

onerror

       An object allowing you to set camera options for this camera: mode, previewSize and recorderProfile.


Examples#

var options = {
mode: 'picture',
recorderProfile: 'jpg',
previewSize: {
width: 352,
height: 288
}
};
var camera = navigator.b2g.cameras.getListOfCameras()[0];
function onSuccess(cameraObj) {
var cameraControl = cameraObj.camera;
// Do stuff with the cameraControl
};
function onError(error) {
console.warn(error);
};
navigator.b2g.cameras.getCamera(camera, options).then(onSuccess, onError);

Permissions#

"permissions": {
"camera": {
"description": "Required for accessing cameras on the device."
}
}