4

I'm working on a mobile app using ionic framework. When I try to work with the cordova camera plugin (to take pictures or access the gallery) the app restarts.

I've found many forum threads and questions here about the subject, and the most useful one was this one: PhoneGap camera restarts the application

This question is 4 years old, and I think the solutions given are no longer compatible with newer version of cordova.

Is there any new solutions to the problem? I've been stuck for 3 days with this.

Community
  • 1
  • 1
younes sofiane
  • 441
  • 1
  • 8
  • 22

3 Answers3

7

The question you mention may be 4 years old, but the issue remains the same: Android is killing off your Cordova app activity while it has been put in the background and the camera activity is in the foreground (see the Cordova documenation for a detailed explanation of the issue).

The essence of the accepted answer to that question is also still correct, but the plugins mentioned are out-of-date / have not been updated for new versions of Cordova.

I would suggest using one of the more recently updated forks (e.g https://github.com/zebra1024/cordova-plugin-wezka-nativecamera) of cordova-plugin-wezka-nativecamera as the foreground camera plugin, since the original repo hasn't been updated in 2 years and has issues with the latest versions of Cordova.

Community
  • 1
  • 1
DaveAlden
  • 30,083
  • 11
  • 93
  • 155
  • Thx for your answer, make things clear, specially why it's happening now on my nexus 5X since I upgraded to android 8.1. Since my 2016, have you head of new possible solution to this problem? – David Dal Busco Jan 10 '18 at 21:07
1

Maybe you have set some platform.resume event listener that is being called after you take the picture. That was the case for me, camera activity does call resume when returning to application, so make sure you have no redirects there, I wonder if there is a way to identify that platform.resume was called by camera actvity. Besides that, always make sure you have latest versions of ionic/cordova/plugins.

ErvalhouS
  • 4,178
  • 1
  • 22
  • 38
-1

maybe your Destination Type in your options variable is set to DATA_URL which causes crashes like mentioned here https://github.com/apache/cordova-plugin-camera#module_Camera.DestinationType

Nevin
  • 365
  • 5
  • 18