title: Phonegap camera function
body: <p>I know there are many questions here about Phonegap and using the camera function. 
  I tried to solve the problem, but still have no solution.</p>
  
  <p>Device is Nexus 7, the camera won´t start after building the app.
  Here is the code:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;script type="text/javascript" src="PhoneGap.js" charset="utf-8"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" charset="utf-8"&gt;
  
  var pictureSource;   // picture source
  var destinationType; // sets the format of returned value 
  
  // Wait for PhoneGap to connect with the device
  //
  document.addEventListener("deviceready",onDeviceReady,false);
  
  // PhoneGap is ready to be used!
  //
  function onDeviceReady() {
      pictureSource=navigator.camera.PictureSourceType;
      destinationType=navigator.camera.DestinationType;
  }
  
  // Called when a photo is successfully retrieved
  //
  function onPhotoDataSuccess(imageData) {
    // Uncomment to view the base64 encoded image data
    // console.log(imageData);
  
    // Get image handle
    //
    var smallImage = document.getElementById('smallImage');
  
    // Unhide image elements
    //
    smallImage.style.display = 'block';
  
    // Show the captured photo
    // The inline CSS rules are used to resize the image
    //
    smallImage.src = "data:image/jpeg;base64," + imageData;
  }
  
  // Called when a photo is successfully retrieved
  //
  function onPhotoURISuccess(imageURI) {
    // Uncomment to view the image file URI 
    // console.log(imageURI);
  
    // Get image handle
    //
    var largeImage = document.getElementById('largeImage');
  
    // Unhide image elements
    //
    largeImage.style.display = 'block';
  
    // Show the captured photo
    // The inline CSS rules are used to resize the image
    //
    largeImage.src = imageURI;
  }
  
  // A button will call this function
  //
  function capturePhoto() {
    // Take picture using device camera and retrieve image as base64-encoded string
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50 });
  }
  
  // A button will call this function
  //
  function capturePhotoEdit() {
    // Take picture using device camera, allow edit, and retrieve image as base64-
  encoded string  
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: 
  true }); 
  }
  
  // A button will call this function
  //
  function getPhoto(source) {
    // Retrieve image file location from specified source
    navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, 
      destinationType: destinationType.FILE_URI,
      sourceType: source });
  }
  
  // Called if something bad happens.
  // 
  function onFail(message) {
    alert('Failed because: ' + message);
  }
  
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;button onclick="capturePhoto();"&gt;Capture Photo&lt;/button&gt; &lt;br&gt;
  </code></pre>
  
  <hr>
  
  <p>tried it with a samsung galaxy s2 ... once again nothing happened!
  i don´t know the problem!?
  here is the code:</p>
  
  <p><strong>androidmainfest.xml permissions:</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;uses-sdk android:minSdkVersion="14" /&gt;
  &lt;uses-permission android:name="android.permission.CAMERA" /&gt;
  &lt;uses-permission android:name="android.permission.VIBRATE" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /&gt;
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.RECEIVE_SMS" /&gt;
  &lt;uses-permission android:name="android.permission.RECORD_AUDIO" /&gt;
  &lt;uses-permission android:name="android.permission.RECORD_VIDEO"/&gt;
  &lt;uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /&gt;
  &lt;uses-permission android:name="android.permission.READ_CONTACTS" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_CONTACTS" /&gt;   
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;   
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.BROADCAST_STICKY" /&gt;
  &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt;
  &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
  
  &lt;uses-feature android:name="android.hardware.camera" /&gt;
  &lt;uses-feature android:name="android.hardware.camera.autofocus" /&gt;
  </code></pre>
  
  <p><strong>and here the code from the html file:</strong></p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;script type="text/javascript" charset="utf-8" src="cordova-2.5.0.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" charset="utf-8"&gt;
  
  var pictureSource;   // picture source
  var destinationType; // sets the format of returned value 
  
  // Wait for PhoneGap to connect with the device
  //
  document.addEventListener("deviceready",onDeviceReady,false);
  
  // PhoneGap is ready to be used!
  //
  function onDeviceReady() {
      pictureSource=navigator.camera.PictureSourceType;
      destinationType=navigator.camera.DestinationType;
  }
  
  // Called when a photo is successfully retrieved
  //
  function onPhotoDataSuccess(imageData) {
    // Uncomment to view the base64 encoded image data
    // console.log(imageData);
  
    // Get image handle
    //
    var smallImage = document.getElementById('smallImage');
  
    // Unhide image elements
    //
    smallImage.style.display = 'block';
  
    // Show the captured photo
    // The inline CSS rules are used to resize the image
    //
    smallImage.src = "data:image/jpeg;base64," + imageData;
  }
  
  // Called when a photo is successfully retrieved
  //
  function onPhotoURISuccess(imageURI) {
    // Uncomment to view the image file URI 
    // console.log(imageURI);
  
    // Get image handle
    //
    var largeImage = document.getElementById('largeImage');
  
    // Unhide image elements
    //
    largeImage.style.display = 'block';
  
    // Show the captured photo
    // The inline CSS rules are used to resize the image
    //
    largeImage.src = imageURI;
  }
  
  // A button will call this function
  //
  function capturePhoto() {
    // Take picture using device camera and retrieve image as base64-encoded string
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50 });
  }
  
  // A button will call this function
  //
  function capturePhotoEdit() {
    // Take picture using device camera, allow edit, and retrieve image as base64- 
  encoded string  
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: 
  true }); 
  }
  
  // A button will call this function
  //
  function getPhoto(source) {
    // Retrieve image file location from specified source
    navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, 
      destinationType: destinationType.FILE_URI,
      sourceType: source });
  }
  
  // Called if something bad happens.
  // 
  function onFail(message) {
    alert('Failed because: ' + message);
  }
  
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;button onclick="capturePhoto();"&gt;Capture Photo&lt;/button&gt; &lt;br&gt;
  &lt;button onclick="capturePhotoEdit();"&gt;Capture Editable Photo&lt;/button&gt; &lt;br&gt;
  &lt;button onclick="getPhoto(pictureSource.PHOTOLIBRARY);"&gt;From Photo Library&lt;/button&gt;&lt;br&gt;
  &lt;button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);"&gt;From Photo 
  Album&lt;/button&gt;&lt;br&gt;
  &lt;img style="display:none;width:60px;height:60px;" id="smallImage" src="" /&gt;
  &lt;img style="display:none;" id="largeImage" src="" /&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>