4

I've been attempting to use the PhoneGap functionality to take a picture with my Android phone and have it saved to the phone's gallery. I didn't have any problems getting their Full example project up and running, but the code never saves the image. We've tested on an Iphone and didn't have any problems, so I'm wondering if I'm doing something wrong or this is yet another Android issue.

Phone Gap Example

The following are the steps that I've taken based on what I've seen online.

Add to the app/res/xml/config.xml file
<plugin name="Camera" value="org.apache.cordova.CameraLauncher" />
Add to the manifest file
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Change the options in getPicture() to include 'saveToPhotoAlbum' option
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
    destinationType: destinationType.DATA_URL, saveToPhotoAlbum: true });

I've also tried changing the destination type to FILE_URI but still had no luck. The application can still display the captured image, so I know it's getting that far, I just don't know why it's not saving to the gallery.

shmattman
  • 71
  • 2
  • 5
  • Im not to familiar with phonegap anymore but the path that phonegap is trying to use to create the image probably doesnt exist or there may not be access to that filepath during the time that the image is being created so the image data gets saved into a bitmap that gets put onscreen but its failing when phonegap is trying to save the image to the file. You may want to write your own native method to save the image. I dont know if the phonegap method automatically saves to appdata in cases when there is no sdcard and that kind of stuff so your own native method may be the best way to go. – James andresakis Jun 24 '13 at 19:48
  • Have you tried [this](http://stackoverflow.com/a/10362355/1473556)? I tried it and it worked without any issues. Put the `movePic()` function at the end of your success handler - `onPhotoDataSuccess()`. Pass the `FILE_URI` as a parameter with the `movePic(FILE_URI)` function call. See if it works for you. – Karan Thakkar Jul 11 '13 at 11:15

1 Answers1

1

I have been remained stuck for the same issue but using jquery mobile. I also copied the working example of apache cordova camera plug in. Simply i just commented the whole code in their provided .js file and paste the following code copied from stack overflow. It worked perfectly fine but with one issue that image will be saved at the bottom with some date of 1970 but it is saved. Code is below.

$('#capturePhotoButton').on('click', function () {
    alert('capturePhotoButton click() called');
    cameraGetPicture();

            });

function cameraGetPicture() {
    navigator.camera.getPicture(imageReceived, cameraFail, {
        quality: 50,
        destinationType: Camera.DestinationType.FILE_URI,
        allowEdit: false,
        saveToPhotoAlbum: true,
        correctOrientation: true        

    });
}

function imageReceived(imageURI) {
    var image = document.querySelector('img#smallImage');
    image.src = imageURI;
    imageURI = new steroids.File({
        path: "image.png",
        relativeTo: steroids.app.userFilesPath

    });
}

function cameraFail(message) {
    alert("Camera error: " + message);
}
Mubashar
  • 11
  • 2