cordova-plugin-camera
cordova-plugin-camera copied to clipboard
Camera plugin crashes app on some android phones when an image is taken
So the plugin works on most of the devices, it works on IOS perfectly. But on android it works on some devices and on some devices once the picture is taken the user is send back to app, app crashes. Now the only thing that I am doing is storing this image in an array. Now one more thing is that if I take a picture and click on retake and then submit the second image the app does not crashes but if I submit the first image it crashes.
Here is my function:
uploadImage() {
this.actionCtrl.create({
title: 'Upload Image',
buttons: [
{
icon: 'camera',
text: 'Open Camera',
handler: () => {
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
sourceType: 1
}
this.camera.getPicture(options).then((imageData) => {
let base64Image = 'data:image/jpeg;base64,' + imageData;
this.images.push(base64Image);
console.log(base64Image);
}, (err) => {
console.log('Error Uploading File')
});
}
},
{
icon: 'image',
text: 'Open Gallery',
handler: () => {
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
sourceType: 0
}
this.camera.getPicture(options).then((imageData) => {
let base64Image = 'data:image/jpeg;base64,' + imageData;
this.images.push(base64Image);
}, (err) => {
console.log('Error Uploading File')
});
}
}
]
}).present();
}
Which version of Android? We are seeing similar issues with an Android 8 device. We are thinking it may be related to the device having an app called Moto Camera installed on it.
Happens on Android 7 Moto C Plus
Happens on Infinix Devices (android 6.0) also.
Using cordova-plugin-background-mode. Enable before camera and then disable after camera is back. It fixed the problem.
It's probably a memory problem and it's how Android behave
I faced that problem too and built a workaround in my Ionic app using the provided Cordova lifecycle, I documented everything in https://forum.ionicframework.com/t/solved-camera-plugin-restart-app-on-android-8-1 if interested
Happens on Android 6 also (Moto G 3G).
Just sometimes console display URI of the new image and then crush or just crash DevApp (Restart). My code:
takePicture(sourceType: PictureSourceType) { var options: CameraOptions = { quality: 20, sourceType: sourceType, // PHOTOLIBRARY or CAMERA targetWidth: 300, targetHeight: 300, destinationType: this.camera.DestinationType.FILE_URI, };
this.camera.getPicture(options).then(imagePath => {
//console.log("getPicture done!", imagePath);
this.profilePic = normalizeURL(imagePath);
console.log("picture normalized done!", this.profilePic);
});
}
Devices Update fixed this issue for me.
yes. Some problem.
It happened on Android 9, which will kill the IonicApp during photo taking. I have 3 android phones, it works well on android 7.0.1, Android 8. This does not happen always, it is unpredictable.
If the app was killed ,there is no way to get data back from life cycle. Because it is not "resume", it was restarted.
Update Camera Plugin and Cordova-android version it will fix this issue
yes. Some problem.
It happened on Android 9, which will kill the IonicApp during photo taking. I have 3 android phones, it works well on android 7.0.1, Android 8. This does not happen always, it is unpredictable.
If the app was killed ,there is no way to get data back from life cycle. Because it is not "resume", it was restarted.
Same problem from my IOS device. IOS 12, iphone 6 plus 64G . some time it works fine , some time after take photo, the app crashed.
@mrHassanRaza I updated to the newest Android Cordova Version 7.1.4 but its the same issue. It crahs the app if I try to get a photo with 8.1.0.
@desmeit is your cordova-plugin-camera plugin version is greater then 4.0 ? if not then update it to latest
Hi,
I'm encoutering the same issues as @yuankunluo / @desmeit / @cymxiao
Here's my ionic info output
β ionic info [0e15ec6]
β Gathering environment info - done!
Ionic:
ionic (Ionic CLI) : 4.2.1
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.2.1
Cordova:
cordova (Cordova CLI) : 8.1.2 ([email protected])
Cordova Platforms : android 7.1.4, ios 4.5.5
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.3.1, (and 13 other plugins)
System:
Android SDK Tools : 26.1.1 (/home/mikaz3/android-sdk-linux)
NodeJS : v8.12.0 (/usr/bin/node)
npm : 6.4.1
OS : Linux 4.15
cordova-plugin-camera
in package.json has version : ^4.0.3
I can also say that taking a picture with the camera works for me but not choosing one from the library (internal storage). i can provide my code aswell if needed.
As pointed by @yuankunluo the lifecycle event doesn't even get fired. The app is set in pause state when opening the photo library, then when choosing the desired picture, the app simply gets put on background as if I had pressed the back button, and when clicking on the app it boots normally. Meaning resume event never gets fired.
I've actually tested all of the above and can provide code for it.
Regards
It seems Android worked on the issue which made it necessary to implement the background plugin. I deactivated the background plugin for devices older than Android 8 and now it worked. I don't know if there is a generally issue with the Background Plugin and Android 8.
if (device.platform.toLowerCase() == 'android' && parseInt( device.version, 10 ) < 8){
cordova.plugins.backgroundMode.enable();
}
It seems Android worked on the issue which made it necessary to implement the background plugin. I deactivated the background plugin for devices older than Android 8 and now it worked. I don't know if there is a generally issue with the Background Plugin and Android 8.
if (device.platform.toLowerCase() == 'android' && parseInt( device.version, 10 ) < 8){ cordova.plugins.backgroundMode.enable(); }
Thanks for the input, will try this ASAP !
So whats the verdict on this? Does enabling the background mode before image capture, fix this?
@ikamikaz3 ?
@sithwarrior We upgraded to [email protected], [email protected] and [email protected] and it seemed to fix most issues with users and the camera. We had to get rid of the backgroundMode plugin as it was causing problems with ios 12.2 so that fix option was not an issue.
@sithwarrior Well, i've managed to get it working with background mode but im not 100% it was caused by this as other users seem to have it working without it,
imho for me it was more a problem on the system ram for the device i was testing on.
My conclusion on this would be to try without it in the first place and make sure you have tons of ram on your android simulator or test on a real device.
@coderroggie @ikamikaz3 Thanks for the response guys. Will try updating the camera plugin.
I am facing same issue. I am using FILE_URI as destinationType. My phone contains lot of free memory, still app crashes when i try to take pictures.
Does anyone help me to understand the root cause for the crash?
@sithwarrior did you tried with upgrading the plugin, please post your results.
Thanks
Which version of Android? We are seeing similar issues with an Android 8 device. We are thinking it may be related to the device having an app called Moto Camera installed on it.
i see crashes on samsung and LG phones with high resolution camera not just moto.
It's probably a memory problem and it's how Android behave
I faced that problem too and built a workaround in my Ionic app using the provided Cordova lifecycle, I documented everything in https://forum.ionicframework.com/t/solved-camera-plugin-restart-app-on-android-8-1 if interested
Its 404, the link provided. Can you elaborate
Hey,
I am also having the similar issue on my Iphone devices where after a photo is taken, the app is restarted. Especially for the devices with high resolution camera. My assumption is that when the camera is opened and the app is placed in background, the IOS terminates the app due to high memory assumption (either coming from the camera or from my app) ? Is there a way to save the state of the app or to prevent the IOS from terminating the app ?
Thanks
It's probably a memory problem and it's how Android behave
I faced that problem too and built a workaround in my Ionic app using the provided Cordova lifecycle, I documented everything in https://forum.ionicframework.com/t/solved-camera-plugin-restart-app-on-android-8-1 if interested
the link is not founded, i have the same issue with a moto g4 plus, i have a feeling that it has to do with the memory. if anyone knows any other solution please share
It's probably a memory problem and it's how Android behave I faced that problem too and built a workaround in my Ionic app using the provided Cordova lifecycle, I documented everything in https://forum.ionicframework.com/t/solved-camera-plugin-restart-app-on-android-8-1 if interested
the link is not founded, i have the same issue with a moto g4 plus, i have a feeling that it has to do with the memory. if anyone knows any other solution please share
@yaksneumann @thesheikhwasim here is the new link: https://forum.ionicframework.com/t/solved-camera-plugin-restart-app-on-android/117828
It crashes on my tablet which has Android 6.0
Hey,
I am also having the similar issue on my Iphone devices where after a photo is taken, the app is restarted. Especially for the devices with high resolution camera. My assumption is that when the camera is opened and the app is placed in background, the IOS terminates the app due to high memory assumption (either coming from the camera or from my app) ? Is there a way to save the state of the app or to prevent the IOS from terminating the app ?
Thanks
Hi @weiz18 , some of our users are having a similar issue and we are finding it nearly impossible to replicate. Did you manage to find a solution, or work out what was happening?
@tenglandct we never managed to find a proper solution. IOS will always kill app to save memory. So i doubt there is a good way to prevent the crash beside limiting the memory consumption of your app. To reproduce, i guess you just need to run a lot of background apps, and then take high quality pictures (with Iphone x max). My advice is to do a fail safe check which make sure that app can restore to previous state the app crashed and reloaded
@weiz18 thank you very much for responding! That is interesting, I think we may have something slightly different going on as one of our users who has reported it is using an older phone (iPhone 6s Plus) and using quite downscaled photos (using the target height/width) and it has only started happening in the last couple of versions. Thank you very much for responding, it is great to get some more information π
I still see the same issue, its just because IONIC cannot manage high resolution pictures and app crashes due to low memory issue. So we shifted to React instead of IONIC.. now we don't see this issue :)
On Tue, Jul 9, 2019 at 9:11 PM tenglandct [email protected] wrote:
@weiz18 https://github.com/weiz18 thank you very much for responding! That is interesting, I think we may have something slightly different going on as one of our users who has reported it is using an older phone (iPhone 6s Plus) and using quite downscaled photos (using the target height/width) and it has only started happening in the last couple of versions. Thank you very much for responding, it is great to get some more information π
β You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/apache/cordova-plugin-camera/issues/345?email_source=notifications&email_token=AFJPJYJ4MYDDT4T7Q7J4JKTP6SWRLA5CNFSM4FVZJL3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZQVN3Y#issuecomment-509695727, or mute the thread https://github.com/notifications/unsubscribe-auth/AFJPJYJW5XW75QFUXHDW3WDP6SWRLANCNFSM4FVZJL3A .
-- β With Regards,
Naga Sundeep. βAsst. Professor, Dept of EEE PBR VITS, Kavali 524201 Nellore D.tβ Andhra Pradesh.