Note that there are some explanatory texts on larger screens.

plurals
  1. POPhonegap Camera not working
    primarykey
    data
    text
    <p>I'm working on a Phonegap app that requires the use of the camera. I took the example from the docs and pasted it into a <code>camera.js</code> file. This project is going to use build Phonegap, but right now I'm doing it locally in an Android project for debugging purposes. In addition, I am using jQuery Mobile for the UI. When I go to the <code>new.html</code> page, the camera does not show up, and when I click the capture new button, I get an error in the <code>index.html</code> page, saying that <code>capturePhoto()</code> is undefined, even though I'm calling that function from the <code>new.html</code> page. Thank you for any help in advance.</p> <p>Here is the code for the <code>new.html</code> page.</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt; &lt;link rel = "stylesheet" href="assets/css/jquery.mobile-1.0.1.min.css" /&gt; &lt;script src="assets/js/jquery.js"&gt;&lt;/script&gt; &lt;script src="assets/js/jquery.mobile-1.0.1.min.js"&gt;&lt;/script&gt; &lt;script src="cordova-2.0.0.js"&gt;&lt;/script&gt; &lt;script src="assets/js/camera.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div data-role="page"&gt; &lt;div data-role="header"&gt; &lt;a href="#" data-rel="back" data-icon="back" data-theme="e"&gt;Back&lt;/a&gt; &lt;h1&gt;New Moment&lt;/h1&gt; &lt;/div&gt;&lt;!-- /header --&gt; &lt;div data-role="content"&gt; &lt;a href="#" data-role="button" data-icon="gear" data-iconpos="right" data-theme="e" onclick="capturePhoto();" &gt;Capture New&lt;/a&gt; &lt;/div&gt;&lt;!-- /content --&gt; &lt;div data-role="footer"&gt; &lt;h4&gt;Company Name Here&lt;/h4&gt; &lt;/div&gt;&lt;!-- /footer --&gt; &lt;/div&gt;&lt;!-- /page --&gt; &lt;img style="display:none;width:60px;height:60px;" id="smallImage" src="small.png" /&gt; &lt;img style="display:none;" id="largeImage" src="large.png" /&gt; &lt;/body&gt; </code></pre> <p></p> <p>Here is the code from the camera.js file.</p> <pre><code>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() { consoe.log("CAPTURE"); // 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); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload