title: PhoneGap Capture Plugin Crashes Android
body: <p>When I use the capture plugin it always crashes the app after taking the picture. When I click the Capture button, it opens the camera app, I take a picture, and click the check mark, then the app closes and says: "Unfortunately, HelloWorld has stopped." Then if I look in the gallery app, the photo is there. Is there anything I'm doing wrong? Or is there something wrong with the plugin?</p>
  
  <p>Here's what I did:</p>
  
  <p>I created a brand new phonegap 3.x (3.1.0-0.15.0 to be exact) project</p>
  
  <pre><code>phonegap create exampleProject
  cd exampleProject
  </code></pre>
  
  <p>and installed the capture plugin</p>
  
  <pre><code>phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture.git
  </code></pre>
  
  <p>which put org.apache.cordova.media-capture in the plugins folder. Then I built the project:</p>
  
  <pre><code>phonegap build android
  </code></pre>
  
  <p>This put org.apache.cordova.file in the plugins folder (because media-capture has a dependency on it), created android.json in the plugins folder. It also creates platforms/android and puts the correct js files in platforms/android/assets/www/plugins and the correct java files in platforms/android/src</p>
  
  <p>I put the following in index.html:</p>
  
  <pre><code>&lt;input type="button" value="Capture" onClick="capture();" /&gt;
  </code></pre>
  
  <p>Here's the entire file:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8" /&gt;
          &lt;meta name="format-detection" content="telephone=no" /&gt;
          &lt;meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /&gt;
          &lt;link rel="stylesheet" type="text/css" href="css/index.css" /&gt;
          &lt;title&gt;Hello World&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div class="app"&gt;
              &lt;h1&gt;PhoneGap&lt;/h1&gt;
              &lt;div id="deviceready" class="blink"&gt;
                  &lt;p class="event listening"&gt;Connecting to Device&lt;/p&gt;
                  &lt;p class="event received"&gt;Device is Ready&lt;/p&gt;
              &lt;/div&gt;
              &lt;input type="button" value="Capture" onClick="capture();" /&gt;
          &lt;/div&gt;
          &lt;script type="text/javascript" src="phonegap.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" src="js/index.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript"&gt;
              app.initialize();
          &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And add the capture(), and getErrorMessage() functions to the end of index.js:</p>
  
  <pre><code>var app = {
      // Application Constructor
      initialize: function() {
          this.bindEvents();
      },
      // Bind Event Listeners
      //
      // Bind any events that are required on startup. Common events are:
      // 'load', 'deviceready', 'offline', and 'online'.
      bindEvents: function() {
          document.addEventListener('deviceready', this.onDeviceReady, false);
      },
      // deviceready Event Handler
      //
      // The scope of 'this' is the event. In order to call the 'receivedEvent'
      // function, we must explicity call 'app.receivedEvent(...);'
      onDeviceReady: function() {
          app.receivedEvent('deviceready');
      },
      // Update DOM on a Received Event
      receivedEvent: function(id) {
          var parentElement = document.getElementById(id);
          var listeningElement = parentElement.querySelector('.listening');
          var receivedElement = parentElement.querySelector('.received');
  
          listeningElement.setAttribute('style', 'display:none;');
          receivedElement.setAttribute('style', 'display:block;');
  
          console.log('Received Event: ' + id);
      }
  };
  
  function capture() {
      var options = { limit: 1 };
      try {
          navigator.device.capture.captureImage(
              function(response) {
                  alert("success: response=" + stringify(response));
              },
              function(CaptureError) {
                  alert('Error: ' + getErrorMessage(CaptureError));
              },
              options
          );
      } catch(e) {
          alert("catch e="+e);
      }
  }
  
  function getErrorMessage(CaptureError) {
    var errorMessage = 'An unknown error occured while trying to get your media, please try again.';
    switch(CaptureError.code) {
      case CaptureError.CAPTURE_NOT_SUPPORTED:
        errorMessage = 'This app does not support the media type.';
        break;
      case CaptureError.CAPTURE_NO_MEDIA_FILES:
        errorMessage = 'No media files returned.';
        break;
      case CaptureError.CAPTURE_INTERNAL_ERR:
        errorMessage = 'The capture process experienced an internal error.';
        break;
      case CaptureError.CAPTURE_APPLICATION_BUSY:
        errorMessage = 'The application was too busy with something else to handle the media capture.';
        break;
      case CaptureError.CAPTURE_INVALID_ARGUMENT:
        errorMessage = 'Values submitted for capture were out of range, notify support.';
        break;
      case 3:
        errorMessage = 'Did you cancel? Please try again.';
        break;
      default:
        break;
    }
    return errorMessage;
  }
  </code></pre>
  
  <p>Then I build the app:</p>
  
  <pre><code>phonegap build android
  </code></pre>
  
  <p>and run it on my android device and experience the mentioned problem</p>