我正在开发Android相机应用程序。我使用cordova插件添加相机
config.xml中
<feature name="Camera">
<param name="android-package" value="org.apache.cordova.camera.CameraLauncher" />
</feature>
拍摄照片的代码
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);
}
}
代码在所有Android版本中都运行良好,期待Android Kitkat。在Kitkat我收到的响应是&#34; 捕获图像时出错&#34;
可以告诉我Kitkat的问题是什么 在此先感谢...!
答案 0 :(得分:0)
你在代码中犯了一个错误。 destinationType: destinationType.FILE_URI,
无效。将该行更改为destinationType: Camera.DestinationType.FILE_URI,
,然后运行。这是您的完整工作代码:
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);
}
}
我建议您使用GapDebug来调试您的应用程序。