Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-1212

When camera is started, and then cancelled with no photo, attempt to read exif data results in fatal error

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.0
    • 2.1.0
    • cordova-android
    • None
    • Dell Streak device using SDK version 7

    Description

      If you start the camera, it loads normally, and then when you click cancel right after that, it causes a fatal error. This is because it's trying to initialize the exif data, but no image exists. What ends up happening is an error when parseInt is called on null. Selected error messages:

      E/AndroidRuntime(3206): Caused by: java.lang.NumberFormatException: unable to parse 'null' as integer
      E/AndroidRuntime(3206): at org.apache.cordova.ExifHelper.getOrientation(ExifHelper.java:167)
      E/AndroidRuntime(3206): at org.apache.cordova.CameraLauncher.onActivityResult(CameraLauncher.java:282)

      I found a fix that works for me by editing CameraLauncher.onActivityResult. I moved the code that deals with exif to inside the conditional:

      if (resultCode == Activity.RESULT_OK) {

      because this is when you know there is an image available. Diff:

      diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java
      index 6d05c64..48c5676 100755
      — a/framework/src/org/apache/cordova/CameraLauncher.java
      +++ b/framework/src/org/apache/cordova/CameraLauncher.java
      @@ -273,19 +273,22 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie

      // If CAMERA
      if (srcType == CAMERA) {

      • // Create an ExifHelper to save the exif data that is lost during compression
      • ExifHelper exif = new ExifHelper();
      • try {
      • if (this.encodingType == JPEG) { - exif.createInFile(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/.Pic.jpg"); - exif.readExifData(); - rotate = exif.getOrientation(); - }
      • } catch (IOException e) { - e.printStackTrace(); - }

        +
        // If image available
        if (resultCode == Activity.RESULT_OK) {
        +
        + // Create an ExifHelper to save the exif data that is lost during compression
        + ExifHelper exif = new ExifHelper();
        + try

        Unknown macro: {+ if (this.encodingType == JPEG) { + exif.createInFile(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/.Pic.jpg"); + exif.readExifData(); + rotate = exif.getOrientation(); + }+ }

        catch (IOException e)

        { + e.printStackTrace(); + }

        +
        try {
        Bitmap bitmap = null;
        Uri uri = null;

      Attachments

        Activity

          People

            macdonst Simon MacDonald
            psnell Phil Snell
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: