Camera
Using Camera API allows to invoke the native camera application to record video or take a picture and receive a path to the file stored.
The methods are static and don't required to create an instance of a camera.
Note that the application will require the user to grant it input simulation and file api permissions for this extension to work on the BlackBerry.
Supported Platform(s)
- BlackBerry OS 5.0+
- BlackBerry PlayBook
| API | OS 5.0 | OS 6.0 | OS 7.0 | PlayBook | Ripple |
|---|---|---|---|---|---|
| close | Y | Y | Y | ||
| takePicture | Y | Y | Y | Y | |
| takeVideo | Y | Y | Y | Y |
Configuration Document Settings
To use all of the API described for this object, you must ensure the following settings are in your configuration document:
You must declare the feature element(s) below in your configuration document:
| Feature ID | OS 5.0 | OS 6.0 | OS 7.0 | PlayBook | Ripple |
|---|---|---|---|---|---|
| <feature id="blackberry.media.camera" /> | Y | Y | Y | Y |
You must declare the permission element(s) below in your configuration document:
| Permission Elements (PlayBook Only) |
|---|
|
- <rim:permit>use_camera</rim:permit> Permits your app to use the camera.
|
close
| static void close() |
Supported Platform(s)
- BlackBerry OS 5.0+Description
Close the camera or video recorder if it's in the foreground.
Code Example(s)
function takeVideo() {
try {
blackberry.media.camera.takeVideo(successCB);
} catch(e) {
alert("Error in supported: " + e);
}
}
function successCB(filePath) {
blackberry.media.camera.close();
// do something with filePath
}
takePicture
| static void takePicture(onCaptured : function, [onCameraClosed: function], [onError: function]) |
Supported Platform(s)
- BlackBerry OS 5.0+- BlackBerry PlayBook
Description
Opens the camera and return a path to the onCaptured callback when a photo is taken.
| Parameter | Type | Description |
|---|---|---|
| onCaptured | function([filePath: String]) |
Method will be invoked when a picture is captured. Expected signature: function onCaptured(filePath)
filePath: Path to a picture captured by the camera. |
| onCameraClosed |
function()
Optional |
Method will be invoked on camera closed event. Expected signature: function onCameraClosed()
|
| onError |
function([e: String])
Optional |
Method will be invoked when an error occurs. Expected signature: function onError(e)
e: Error message |
takeVideo
| static void takeVideo(onCaptured : function, [onCameraClosed: function], [onError: function]) |
Supported Platform(s)
- BlackBerry OS 5.0+- BlackBerry PlayBook
Description
Opens the camera and return a path to the onCaptured callback when a video is taken.
| Parameter | Type | Description |
|---|---|---|
| onCaptured | function([filePath: String]) |
Method will be invoked when a video is recorded. Expected signature: function onCaptured(filePath)
filePath: Path to a video captured by the camera. |
| onCameraClosed |
function()
Optional |
Method will be invoked on camera closed event. Expected signature: function onCameraClosed()
|
| onError |
function([e: String])
Optional |
Method will be invoked when an error occurs. Expected signature: function onError(e)
e: Error message |
Code Example(s)
function takeVideo() {
try {
blackberry.media.camera.takeVideo(successCB, closedCB, errorCB);
} catch(e) {
alert("Error in supported: " + e);
}
}
function successCB(filePath) {
alert("Succeed: " + filePath);
}
function closedCB() {
alert("Camera closed event");
}
function errorCB(e) {
alert("Error occured: " + e);
}