Phone camera: camera does not work in Android kitkat

I am developing an Android application in an Android application. I add a camera using the cordova plugin

config.xml

<feature name="Camera"> <param name="android-package" value="org.apache.cordova.camera.CameraLauncher" /> </feature> 

code for shooting

  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 works fine in all versions of Android awaiting Android Kitkat. In Kitkat, I get the answer as " Image Capture Error "

can someone tell me what the problem is in Kitkat Thanks in Advance ...!

+5
source share
1 answer

You made a mistake inside your code. destinationType: destinationType.FILE_URI, will not work. Instead, change this line to destinationType: Camera.DestinationType.FILE_URI, , and it will start. Here is 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 use GapDebug to debug your applications.

0
source

All Articles