我正在开发一个应用程序在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有什么问题吗?谢谢!
发布于 2015-07-14 09:02:23
你在代码里犯了个错误。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来调试应用程序。
https://stackoverflow.com/questions/31398916
复制相似问题