App stops after Camera Usage Ionic-Native


#1

In my app takePicture() fxn is there to initate camera and save the image but…when i click ok after the picture preview the app is getting stopped.

camerPage.ts

   takePicture(){


      const options: CameraOptions = {
        quality: 100,
        destinationType: this.camera.DestinationType.DATA_URL,
        encodingType: this.camera.EncodingType.JPEG,
        mediaType: this.camera.MediaType.PICTURE
      }

      this.camera.getPicture(options).then((imageData)=>{
         this.base64Image = 'data:image/jpeg;base64,'+imageData;
      },(err)=>{
        alert("EROOR IN SAVING PC");
      });
   }

And in html the fxn is called.

Can anyone tell what may be the issue here???


#2

Are you using https://ionicframework.com/docs/native/camera/?
What platform? What Ionic version (ionic infofrom CLI please)?


#3

Hello!

Have a look also at:

DATA_URL: Return base64 encoded string. DATA_URL can be very memory intensive and cause app crashes or out of memory errors. Use FILE_URI or NATIVE_URI if possible.

It looks like if you use DATA URL your device might not be able to handle it and it crashes for that reason.

You should use platform to detect if its android or iOS, then use FILE_URI for android and NATIVE_URI for iOS.

Hope it helps!


#4

@El_Pollito_Pio - this doesn’t work for me. I still keep getting “Unfortunately, MyApp has stopped”. Is there anything else I could try?

Thanks


#5

Are you by chance creating the function before you declare camera? I.e., above the constructor? Is the camera set to private as opposed to public?
Just a couple of maybes


#6

Hey @jaydz,

Thanks for the reply. So I changed private to public and DATA_URI to FILE_URI, and that seemed to clear things up a bit. The app doesn’t crash anymore. So it is using lesser memory.

However, I need to upload the image I take to an external service using a POST request, and therefore DATA_URI (base64 string of the image) is the only way forward. Is there any chance I could continue using DATA_URI and still not use more than the memory allotted to the app?

Thanks


#7

Might seem like a silly question, but have you tried just changing private to public and uploading DATA_URI?

If not, try it. Take the scientific method approach and eliminate possibilities 1 at a time.

If you have tried it and it’s crashing your app still, it’s beyond my scope of knowledge. I’m not sure.

Unless there’s some other reason that DATA_URI can’t be used in your scenario and I’m just unaware or not thinking of it of course


#8

@jaydz, I used the scientific method alright :smile:

It seems to be a problem during development, but it previously worked as a full app (with the apk). Hopefully it will work once I publish it.


#9

Happy to hear it! Good luck!!