5

We are using Cordova 5.0.0 and its cordova-camera-plugin

When we are testing it on Android, the app crashes when the user takes a photo. Looking at the links below, it seems that our app is being killed while the camera app it on front.

PhoneGap camera restarts the application

https://github.com/shaithana/cordova-plugin-wezka-nativecamera

While there are some answers but it seems to be outdated: The foreground camera plugin is not suitable to newer devices or Cordova and other solutions didn't work for us

Does anyone have an up-to-date solution?

Community
  • 1
  • 1
David Salzer
  • 872
  • 1
  • 7
  • 24
  • Cordova camera plugin just uses an intent to the camera app. When you use intents, the app that called the intent might be killed if the device runs out of memory. My point is, there is no solution for this other than using another camera plugin. If the one you link doesn't work, ask the plugin author to update. But why do you say it's not suitable for newer cordova? – jcesarmobile Nov 12 '15 at 08:13
  • We are using this plugin for a while and it seems like itvis getting worse with newer versions – David Salzer Nov 12 '15 at 14:49
  • 1
    Try to use this forked [cordova-android](https://github.com/apache/cordova-android/pull/239) and [cordova-plugin-camera](https://github.com/MSOpenTech/cordova-plugin-camera/tree/save-state-plugin-only). The docs, sample and discussion on the approach used can be found in the cordova-android PR. – daserge Nov 17 '15 at 15:56
  • @daserge I am sorry you didn't answer in a real SO answer. The bounty should be yours.. – David Salzer Nov 21 '15 at 16:25

2 Answers2

3

Try to use this forked cordova-android and cordova-plugin-camera.

The docs, sample and discussion on the approach used can be found in the cordova-android PR.

BTW, the PRs are going to be merged soon.

daserge
  • 1,512
  • 12
  • 18
0

First question that comes to my mind is: Why using this camera plugin: https://github.com/shaithana/cordova-plugin-wezka-nativecamera

It's obviously a fork. You might have a good reason for that. It's also outdated. Last contribution was one year ago.

Maybe you want to give the "official" plugin a shot: https://github.com/apache/cordova-plugin-camera

Going deeper into detail without knowing more about your testing environment (which device(s) with which Android version) and without having possibility to review entire related code, is not possible and answers may not give any reliable advice for change.

Have you ensured, that the call to the camera plugin cannot happen before "deviceready" was triggered? Is cordova.js loaded?

Update: You may also want to switch from raw alerts to console output. I recognized several times that alerts in callbacks triggered from plugins could cause some trouble.

As a general rule of thumb: Use console.log() instead of alert() and connect with Chrome (chrome://inspect) to the emulator or device to see what happens. You can additionally use adb logcat to have a look into the device log.

Axel
  • 435
  • 4
  • 4
  • This answer got a bounty just because there is no other answer now and SO gives half the bounty to that answer. However this is not an answer to my question... I know the official plugin and it crushed. I guess you didn't even try. Logging has nothing to do with it. – David Salzer Nov 21 '15 at 16:20
  • For me, the official cordova camera plugin works just fine on Android and iOS in several projects. You don't deliver enough relevant information to allow analysis and targeted help. Did you already check the device logs during a app session with adb logcat? Any exception there? Did you check that all versions (cordova cli, platforms etc.) are correct? Did you verify memory consumption? Is there free storage on the device? I'm not a clairvoyant and do not have a crystal ball. Please feel free to deliver more information... ;) – Axel Nov 22 '15 at 18:57