title | description |
---|---|
Android Photo |
Take photos with the camera on Android. |
Travis CI |
---|
This plugin defines a global navigator.photo
object, which provides an API for taking photos with the camera on Android.
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.photo);
}
- Android
cordova plugin add cordova-plugin-android-photo
It is also possible to install via repo url directly (unstable)
cordova plugin add https://github.com/shaunjohansen/cordova-plugin-android-photo.git
Contributors are welcome! You can report bugs, improve the documentation, or contribute code.
And don't forget to test and document your code.
- photo
- .takePicture(successCallback, errorCallback)
- .errorCallback :
function
- .successCallback :
function
Takes a photo using the camera. The image is passed to the success callback as the URI for the image file.
The photo.takePicture
function opens the device's default camera
application which allows users to snap a photo.
Once the user snaps the photo, the camera application closes and the application is restored.
The image file location is sent to the successCallback
callback function.
Kind: static method of camera
Param | Type |
---|---|
successCallback | successCallback |
errorCallback | errorCallback |
navigator.photo.takePicture(successCallback, errorCallback);
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 the Android Lifecycle guide
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.
Callback function that provides an error message.
Kind: static typedef of camera
Param | Type | Description |
---|---|---|
message | string |
The message is provided by the device's native code. |
Callback function that provides the image uri.
Kind: static typedef of camera
Param | Type | Description |
---|---|---|
imageUri | string |
The image file URI. |
// Show image
//
function cameraCallback(imageUri) {
var image = document.getElementById('myImage');
image.src = imageUri;
}
- Cross-browser testing platform and open source <3 provided by Sauce Labs