In the config.xml file I've added
<plugin name="cordova-plugin-camera" /> <plugin name="cordova-plugin-media-capture"/>
In the index.html file
<script type="text/javascript" charset="utf-8" src="cordova.js"></script> ... <button onclick="capturePhoto();">Capture Photo</button>
Then in the Javascript tag
<script>
var pictureSource; // picture source
var destinationType; // sets the format of returned value
// Wait for device API libraries to load
document.addEventListener("deviceready",onDeviceReady,false);
// device APIs are available
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
// Called when a photo is successfully retrieved
function onPhotoDataSuccess(imageData) {
// Uncomment to view the base64-encoded image data
alert(imageData);
// Get image handle
var smallImage = document.getElementById('smallImage');
// Unhide image elements
smallImage.style.display = 'block';
// Show the captured photo
// The inline CSS rules are used to resize the image
smallImage.src = "data:image/jpeg;base64," + imageData;
}
function capturePhoto() {
alert("I am here");
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
destinationType: Camera.DestinationType.DATA_URL
});
}
function onFail(message) {
alert('Failed because: ' + message);
}
</script>
On the button click I am getting the alert 'I am here' which mean the html button is calling the capturePhoto() function. And I am not getting any error alert!
But the camera is not opening!
I am using the online https://build.phonegap.com/ in order to get the apk
I've been stuck on this for a while.. any advice please ?
I solved it by adding an older version of 'cordova-plugin-camera' using spec="2.0"
<plugin name="cordova-plugin-camera" spec="2.0" />
and also added
<feature name="Camera"> <param name="android-package" value="org.apache.cordova.CameraLauncher" /> </feature>
Does anyone know what's the latest 'cordova-plugin-camera' version that is compatible with cli-6.5.0 ?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.