revan1990
revan1990

Reputation: 141

Cordova camera saves to gallery even on false

I'm in a really nasty situation...

My client wants a Cordova application in Ionic Framework v1, and it's imperative that the camera does not save images to gallery. However, when I set the parameter for saving to gallery to false, it is still saving to gallery.

The problem occurs on Android when you take a photo and cancel it. It then saves that picture to gallery and sometimes even saves all other pictures after that.

I would really welcome any kind of help; All I've found so far are some solutions that I find really hard to understand since my knowledge of Java is zero.

Here is my JS code

function capturePhoto() {
    var maxDimension = 1280;
    var options = {
      quality: 80,
      destinationType: Camera.DestinationType.DATA_URL,
      sourceType: Camera.PictureSourceType.CAMERA,
      correctOrientation: true,
      targetWidth: maxDimension,
      targetHeight: maxDimension,
      saveToPhotoAlbum: false

    };

This is for camera options.

 $cordovaCamera.getPicture(options).then(function (imageData) {
      var src = "data:image/jpeg;base64," + imageData;
      $scope.photoPreviewSrc = src;
    }).catch(function (err) {

    });
  }

Upvotes: 14

Views: 1799

Answers (3)

EdH
EdH

Reputation: 3303

Is it really going to the photo gallery, or just showing up in Android's photo app? The Android default photo browser will show all photos, screenshots, etc. It will also even show just random images - that other Apps may have on the file system, but that aren't photos.

Since in cordova, you don't have great control of the OS, you can use a work around: You can place the images in a hidden directory (starting with a . such .appdata) and this will prevent Android from automatically seeing the images from the "Gallery" app. I had this problem in an Ionic App and solved it that way.

Upvotes: 0

Ethan May
Ethan May

Reputation: 1302

You may want to try running something like the following after you receive the image data:

navigator.camera.cleanup(onSuccess, onFail);

function onSuccess() {
    console.log("Camera cleanup success.")
}

function onFail(message) {
    alert('Failed because: ' + message);
}

From the docs: "camera.cleanup() Removes intermediate image files that are kept in temporary storage after calling camera.getPicture. Applies only when the value of Camera.sourceType equals Camera.PictureSourceType.CAMERA and the Camera.destinationType equals Camera.DestinationType.FILE_URI."

The above relates directly to your use case.

Upvotes: 0

bvakiti
bvakiti

Reputation: 3631

I have checked with your code using cordova. It works fine as expected. Verify your app in other device once.

I haven't checked it on ionic platform.

Upvotes: 2

Related Questions