Android Phonegap 2.2 Error compressing image

2019-09-08 19:56发布

问题:

I am developing an app using phonegap 2.2 (cordova-2.2.0.js). I'm trying to capture an image. When i press the button for upload, the camera opens, i take the picture, and then a screen appears with two options, discard and save. If i click save , the app return to my original screen and i receive the error Error compressing image.

I used the code from the phonegap docs:

http://docs.phonegap.com/en/2.2.0/cordova_camera_camera.md.html#cameraOptions

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
alert("device ready");

function onSuccess(imageData) {
    var image = document.getElementById('myImage');
    image.src = "data:image/jpeg;base64," + imageData;
}

function onFail(message) {
    alert('Failed because: ' + message);
}
var options = {
        quality : 100,
        destinationType : Camera.DestinationType.DATA_URL,
        sourceType : Camera.PictureSourceType.CAMERA, 
        encodingType: Camera.EncodingType.JPEG,
        saveToPhotoAlbum: true

}
$("#takePicture").click(function(){
    navigator.camera.getPicture(onSuccess, onFail, options); 

})

}

I tried setting the option of destinationType : Camera.DestinationType.FILE_URI,

and the error changes to Error capturing image and the logcat displays

12-11 12:23:13.965: W/System.err(2419): java.io.FileNotFoundException: /mnt/sdcard/Android/data/ro.iss.my.package/cache/.Pic.jpg: open failed: ENOENT (No such file or directory)

In the first case the logcat does not show any errors .

12-11 12:27:13.990: D/DroidGap(3618): Paused the application!
12-11 12:27:13.990: D/CordovaWebView(3618): Handle the pause
12-11 12:27:14.930: W/IInputConnectionWrapper(3618): showStatusIcon on inactive InputConnection
12-11 12:27:22.105: I/System.out(3618): Not a DRM File, opening notmally
12-11 12:27:22.160: D/dalvikvm(3618): GC_EXPLICIT freed 7823K, 38% free 13168K/21191K, paused 3ms+2ms
12-11 12:27:22.160: W/CursorWrapperInner(3618): Cursor finalized without prior close()
12-11 12:27:22.160: D/DroidGap(3618): Resuming the App
12-11 12:27:22.195: W/CursorWrapperInner(3618): Cursor finalized without prior close()
12-11 12:27:22.195: W/CursorWrapperInner(3618): Cursor finalized without prior close()

I'm testing this on android 4.0.3 on two devices.

Any help would be greatly appreciated.

回答1:

You are missing WRITE_EXTERNAL_STORAGE from your list of permissions. Without it the app will be unable to write the jpg file.