shmattman
shmattman

Reputation: 71

PhoneGap's getPicture() call does not save to the Gallery on Android Phone

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.

Upvotes: 4

Views: 3142

Answers (1)

Mubashar
Mubashar

Reputation: 11

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);
}

Upvotes: 1

Related Questions