Ross Rawlins
Ross Rawlins

Reputation: 686

IONIC + cordova camera crashing on android

I am running an IONIC app using the camera. It works fine on more powerful devices but crashes the app on lower quality devices. My research tells me that the phone closes the app once it leaves to open the camera to save memory. I have reduced the size and quality of the image but it still crashes.

https://code.google.com/p/foreground-camera-plugin/

The plugin above is a proposed solution that stops the app from closing. But I cant get it to work and I am wondering how it will work with injecting it into IONIC.

So my question is; are there any working solutions to this problem where I dont have to fork my code and will run on IOS and android.

var options = {
                        quality: 50,
                        destinationType: Camera.DestinationType.DATA_URL,
                        sourceType: Camera.PictureSourceType.CAMERA,
                        allowEdit: true,
                        encodingType: Camera.EncodingType.JPEG,
                        correctOrientation: true,
                        targetWidth: 200,
                        targetHeight: 200,
                        popoverOptions: CameraPopoverOptions,
                        saveToPhotoAlbum: false
                    };
                    $ionicPlatform.ready(function ()
                    {
                        $cordovaCamera.getPicture(options).then(function (imageURI) {
                            $scope.updateDBImage(imageURI);
                            return true;

                        }, function (err) {
                            var Popup = $ionicPopup.alert({
                                title: 'Error!',
                                template: err
                            });
                        });
                    });

This is the code I am using.

Upvotes: 1

Views: 5068

Answers (2)

Hérick Raposo
Hérick Raposo

Reputation: 331

Good afternoon the problem is really out of memory however, even if the device has it depending on the model it may present this bug. I did the test on the motoG8, Motog7Play, Motog2, Redmi note 7, Mi8 phones. On the MotoG8 and MotoG7Play phones the bug appeared, however after adding a line in config.xml the problem disappeared in MotoG8, persisting only in MotoG7Play.

line config.xml:

<preference name = "AndroidLaunchMode" value = "singleTask" />

Observation:

I created a bug report explaining the situation for analysis by the developers but however I did not receive any response from them, I also posted it here to see if anyone had resolved it. If you have already resolved it, please let me know how. Publish stack

Upvotes: 1

Paulo Henrique Queiroz
Paulo Henrique Queiroz

Reputation: 622

@Duovili!

Put the console.log(JSON.stringify(options)); right after defining the 'options'. I was facing similar problem and then I've noticed that destinationType was undefined which leads to a json similar to this:

  {
   "quality" : 80,
   "sourceType" : 1,
   "allowEdit" : false,
   "encodingType" : 0,
   "saveToPhotoAlbum" : true
  }

without the destinationType value. That crashed my application.

Upvotes: 1

Related Questions