Phonegap : Camera not working in android kitkat

守給你的承諾、 提交于 2020-01-03 14:00:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!