0

I use the following code to get in Phonegap (cordova 1.9.0) a photo from a gallery or from camera and include it in the page:

function getPhotoByGallery() {
    navigator.camera.getPicture(onPhotoSuccess, onFail, {
        quality : 50,
        destinationType: navigator.camera.DestinationType.FILE_URI,
        sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
    });
}

function getPhotoByCamera() {
    navigator.camera.getPicture(onPhotoSuccess, onFail, {
        quality : 50
    });
}

function onPhotoSuccess(data) {
    var viewport = document.getElementById('viewport');
    //console.log(data);
    viewport.style.display = "";
    document.getElementById("test_img").src = data;
}

Test-Device: Samsung Galaxy S3 with Android 4. Getting the Photos with the camera is no problem. But when I try to take a photo from the gallery several times, the app crashes frequently (without any usefull error) Not all the time but often and in different cycles. (Sometimes when picking an image from the gallery the third time, sometimes the fifth time and so on)

I have no idea what the cause of the problem could be since the app doesn't give me any feedback of the problem it encountered...

  • What version of Phonegap are you using? I've fixed a lot of Camera issues for the upcomming 2.0.0. Also, run "adb logcat" to see what the error is from the OS. – Simon MacDonald Jul 13 '12 at 17:36

3 Answers3

0

I was having the same problem for 2 days until I fount that you should have access to the permission of getting the image file you took in the device. By default there is no permission of return the image so it returns null and your app crashes.

If you are using Cordova/PhoneGap in XCode then you should also create the Config.xml file in www folder and give permission to acces the image file.

<feature name="http://api.phonegap.com/1.0/device" />
<feature name="http://api.phonegap.com/1.0/battery"/>
<feature name="http://api.phonegap.com/1.0/camera"/>
<feature name="http://api.phonegap.com/1.0/contacts"/>
<feature name="http://api.phonegap.com/1.0/file"/>
<feature name="http://api.phonegap.com/1.0/geolocation"/>
<feature name="http://api.phonegap.com/1.0/media"/>
<feature name="http://api.phonegap.com/1.0/network"/>
<feature name="http://api.phonegap.com/1.0/notification"/>

If you are working on Android then give permission on the AndroidManifest.xml file.

you can find everything for the config.xml file here: https://build.phonegap.com/docs/config-xml

There is no issue in the Cordova/PhoneGap.

uzair
  • 56
  • 4
0

I'm suddenly having the same issue with an app running on Android 4 (Samsung Galaxy III) and PhoneGap 2.0 (built via PhoneGap Build).

As a side point, the only permissions that are needed are:

<feature name="http://api.phonegap.com/1.0/camera"/>
<feature name="http://api.phonegap.com/1.0/file"/>

which I have set (it works on an Android 2.2 phone).

UPDATE After further testing it turns out that the problem is a well known one where Android closes open apps when it needs more memory, e.g. when it opens the webcam.

Ian Devlin
  • 18,534
  • 6
  • 55
  • 73
-1

Is the device rooted? if so you can use a logcat program (such as alogcat) to try and help.

user319940
  • 3,267
  • 8
  • 38
  • 53