Phonegap:相机无法在android kitkat中运行

5 android phonegap-plugins cordova phonegap-build

我正在开发Android相机应用程序.我使用cordova插件添加相机

config.xml中

 <feature name="Camera">
    <param name="android-package" value="org.apache.cordova.camera.CameraLauncher" />
</feature>
Run Code Online (Sandbox Code Playgroud)

拍照的代码

 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);
    }
}
Run Code Online (Sandbox Code Playgroud)

代码在所有Android版本中都运行良好,期待Android Kitkat.在Kitkat我得到的响应为" 错误捕获图像 "

可以告诉我Kitkat的问题在此先感谢...!

Sit*_*hys 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);
             }
    }
Run Code Online (Sandbox Code Playgroud)

我建议您使用GapDebug来调试您的应用程序。