问题
I am developing an App in Android for camera application. I add the camera using cordova plugin
config.xml
<feature name="Camera">
<param name="android-package" value="org.apache.cordova.camera.CameraLauncher" />
</feature>
code for taking Picture
function snapPicture () {
navigator.camera.getPicture (onSuccess, onFail,
{ quality: 100,
sourceType: navigator.camera.PictureSourceType.CAMERA,
mediaType: navigator.camera.MediaType.PICTURE,
destinationType: destinationType.FILE_URI,
encodingType: navigator.camera.EncodingType.JPEG,
correctOrientation: false,
saveToPhotoAlbum: true
});
//A callback function when snapping picture is success.
function onSuccess (imageData) {
var image = document.getElementById ('picture');
alert("path : "+imageData);
image.src = imageData;
}
//A callback function when snapping picture is fail.
function onFail (message) {
alert ('Error occured: ' + message);
}
}
The code is working fine in all Android version expect Android Kitkat. In Kitkat am getting the response as "Error capturing image"
can any tell me what is the issue in Kitkat Thanks in Advance ...!
回答1:
You made a mistake inside your code. destinationType: destinationType.FILE_URI,
will not work. Change that line to destinationType: Camera.DestinationType.FILE_URI,
instead and it'll run. Here's your full working code:
function snapPicture() {
navigator.camera.getPicture(onSuccess, onFail, { quality: 100,
sourceType: navigator.camera.PictureSourceType.CAMERA,
mediaType: navigator.camera.MediaType.PICTURE,
destinationType: Camera.DestinationType.FILE_URI,
encodingType: navigator.camera.EncodingType.JPEG,
correctOrientation: false,
saveToPhotoAlbum: true
})
//A callback function when snapping picture is success.
function onSuccess (imageData) {
var image = document.getElementById ('picture');
alert("path : "+imageData);
image.src = imageData;
}
//A callback function when snapping picture is fail.
function onFail (message) {
alert ('Error occured: ' + message);
}
}
I recommend you to use GapDebug to Debug your Applications.
来源:https://stackoverflow.com/questions/31398916/phonegap-camera-not-working-in-android-kitkat