I'm using PhoneGap's navigator.camera.getPicture
function to retrieve a photo from the device's camera on Android.
function onSuccess(imageData) {
alert("Success!");
}
function onFail(message) {
alert('Failed because: ' + message);
}
$(function() {
$("button").tap(function() {
navigator.camera.getPicture(onSuccess, onFail, { quality: 50 });
});
});
When I click the button, it does start the camera, but when I click OK on the camera app after taking a photo, it restarts the application.
I tried to:
- use different source types.
- use different destination types.
- reduce quality.
Any ideas?
EDIT: I also started an issue at github.
I have a Samsung Galaxy Note II. I had the same problem. I changed this in the AndroidManifest.xml and now it works on Samsung and HTC Thunderbolt
When Android relaunches the app after the picture has been taken, a
resume
event is sent to the app. The event contains the taken photo data. So, a possible workaround involves catching the event:Of course, you also have to restore the state of the application. For that, save your state information to eg. localStorage before opening the camera.
I am having a similar problem where even the full example provided at Camera Documentation crashes the application on an Android device (Samsung, Galaxy S). Here is a output of the log that I get:
This is actually happening when your device activities are being killed by Garbage collector , when some of your app event is trigered, your default activity goes at background hence it is being killed.
To fix this you need to go to Developer Options There you will see the option Don't Keep Activities , just uncheck that. restart your app and try camera now. it will work smoothly.
For me it helped to use cordova background plugin: https://www.npmjs.com/package/cordova-plugin-background-mode
Include into config.xml:
Then trigger click event to start camera plugin and send app to background:
Do not forget to disable background mode in case of success by camera plugin:
To be sure also disable it onResume and enable it onPause:
Note that if you are testing this applications directly on your Android phone, there's an option inside "Developer options" called "Don't keep activities". When this option is checked it eliminates the activity when you leave it. Specifically in the case of the camera (and other applications lunched from your activity) it will restart your activity.
Uncheck this and see if that helps.