Note that there are some explanatory texts on larger screens.

plurals
  1. POPhoneGap for android- Camera API .. Not working with Jquery mobile
    primarykey
    data
    text
    <p>I am new learner with Phonegap and JqueryMobile. I have made separate project in eclipse with just phonegap Camera API code. Its working fine in emulator. But when I integrate same code in another project with Jquery mobile, it is throwing exception <strong>(Uncaught TypeError: Cannot read property 'PNG' of undefined at file:///android_asset/www/index.html:347)</strong>. Without this camera api code is working fine.</p> <p><strong>(1) Working code- just phonegap</strong> </p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Capture Photo&lt;/title&gt; &lt;script type="text/javascript" charset="utf-8" src="cordova-2.0.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 var encodingType; // 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() { console.log("onDeviceReady"); pictureSource=navigator.camera.PictureSourceType; console.log("onDeviceReady1"); destinationType=navigator.camera.DestinationType; console.log("onDeviceReady2"); encodingType=navigator.camera.EncodingType; } // Called when a photo is successfully retrieved // function onPhotoDataSuccess(imageData) { // Uncomment to view the base64 encoded image data console.log(imageData); var re = /\?(\d*)$/; imageData=imageData.replace(re, ""); alert("imageData is "+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); // alert("uri is "+imageURI); var re = /\?(\d*)$/; imageURI=imageURI.replace(re, ""); alert("imageURI is "+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: 100, targetWidth: -1, targetHeight: -1, encodingType:encodingType.PNG }); } // 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: 100, allowEdit: true, targetWidth: -1, targetHeight: -1 ,encodingType:encodingType.PNG, }); } // A button will call this function // function getPhoto(source) { // Retrieve image file location from specified source navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 100, targetWidth: -1, targetHeight: -1 , destinationType: destinationType.FILE_URI,encodingType:PNG, 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="width:60px;height:60px;" id="smallImage" src="a.png" /&gt; &lt;img style="" id="largeImage" src="a.png" /&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>(2) Not Working code- jquerymobile + phonegap</strong> </p> <pre><code> &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8" /&gt; &lt;meta name="viewport" content="width=device-width, initial-scale=1" /&gt; &lt;title&gt; &lt;/title&gt; &lt;link rel="stylesheet" href="jquery.mobile-1.1.1.min.css" /&gt; &lt;link rel="stylesheet" href="my.css" /&gt; &lt;style&gt; /* App custom styles */ &lt;/style&gt; &lt;script src="jquery.min.js"&gt; &lt;script type="text/javascript" charset="utf-8" src="cordova-2.0.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 var encodingType; // 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() { console.log("onDeviceReady"); pictureSource=navigator.camera.PictureSourceType; console.log("onDeviceReady1"); destinationType=navigator.camera.DestinationType; console.log("onDeviceReady2"); encodingType=navigator.camera.EncodingType; } // Called when a photo is successfully retrieved // function onPhotoDataSuccess(imageData) { // Uncomment to view the base64 encoded image data console.log(imageData); var re = /\?(\d*)$/; imageData=imageData.replace(re, ""); alert("imageData is "+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); // alert("uri is "+imageURI); var re = /\?(\d*)$/; imageURI=imageURI.replace(re, ""); alert("imageURI is "+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: 100, targetWidth: -1, targetHeight: -1, encodingType:encodingType.PNG }); } // 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:50, destinationType:Camera.DestinationType.DATA_URL }); } // A button will call this function // function getPhoto(source) { // Retrieve image file location from specified source navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 100, targetWidth: -1, targetHeight: -1 , destinationType: destinationType.FILE_URI,encodingType:PNG, sourceType: source }); } // Called if something bad happens. // function onFail(message) { alert('Failed because: ' + message); } &lt;/script&gt; &lt;script src="jquery.mobile-1.1.1.min.js"&gt; &lt;/script&gt; &lt;script src="my.js"&gt; &lt;/script&gt; &lt;script src="local.js"&gt; &lt;/script&gt; &lt;script src="jqm.autoComplete.min-1.4.2.js"&gt; &lt;/script&gt; &lt;script src="camera.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;!-- Home --&gt; &lt;div data-role="page" id="page1"&gt; &lt;script&gt; var Countrydata=''; $("#page1").bind("pageshow", function(e) { var myXML = "" var availableTags = ""; var request = new XMLHttpRequest(); request.open("GET", "Countries.xml", true); request.onreadystatechange = function(){ if (request.readyState == 4) { if (request.status == 200 || request.status == 0) { myXML = request.responseXML; parseXml(myXML); } } } request.send(); function parseXml(xml) { $(xml).find('Country').each(function(){ if(Countrydata !='') { Countrydata += ','; } Countrydata += $(this).text(); }); availableTags = Countrydata; } availableTags = ['India']; $("#searchinput1").autocomplete({ target: $('#suggestions'), source: availableTags, minLength: 1, matchFromStart: false, callback: function(e) { var $a = $(e.currentTarget); // access the selected item $('#searchinput1').val($a.text()); // place the value of the selection into the search box $("#searchinput1").autocomplete('clear'); // clear the listview } }); }); &lt;/script&gt; &lt;div data-theme="b" data-role="header"&gt; &lt;h2&gt; Nalco Water Savings Unit &lt;/h2&gt; &lt;/div&gt; &lt;div data-role="content" style="padding: 15px" data-theme="b"&gt; &lt;div data-role="navbar" data-iconpos="right"&gt; &lt;ul&gt; &lt;li&gt; &lt;a href="#" data-icon="arrow-r" &gt; Customer Info &lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#page2" data-icon="arrow-r"&gt; Additional Details &lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#page3" data-icon="info"&gt; Summary &lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div data-role="collapsible-set" data-content-theme="b"&gt; &lt;div data-role="collapsible" data-collapsed="false"&gt; &lt;h3&gt; Company details &lt;/h3&gt; &lt;div data-role="fieldcontain"&gt; &lt;fieldset data-role="controlgroup" data-mini="true"&gt; &lt;label for="textinput3"&gt; Company number &lt;/label&gt; &lt;input name="txtCompNumber" id="textinput3" placeholder="" value="" type="text" /&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;div data-role="fieldcontain"&gt; &lt;fieldset data-role="controlgroup" data-mini="true"&gt; &lt;label for="textinput4"&gt; Company Address &lt;/label&gt; &lt;input name="txtCompAddr" id="textinput4" placeholder="" value="" type="text" /&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;div data-role="fieldcontain"&gt; &lt;fieldset data-role="controlgroup" data-mini="true"&gt; &lt;label for="textinput5"&gt; City &lt;/label&gt; &lt;input name="txtCity" id="textinput5" placeholder="" value="" type="text" /&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;div data-role="fieldcontain"&gt; &lt;fieldset data-role="controlgroup" data-mini="true"&gt; &lt;label for="searchinput1"&gt; Country &lt;/label&gt; &lt;input id="searchinput1" placeholder="...Serach for country" type="text" /&gt; &lt;ul id="suggestions" data-role="listview" data-inset="true"&gt;&lt;/ul&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;/div&gt; &lt;div data-role="collapsible" data-collapsed="true"&gt; &lt;h3&gt; Customer Name &lt;/h3&gt; &lt;div data-role="fieldcontain"&gt; &lt;fieldset data-role="controlgroup" data-mini="true"&gt; &lt;label for="textinput1"&gt; Customer Name &lt;/label&gt; &lt;input name="txtCustName" id="textinput1" placeholder="" value="" type="text" /&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;/div&gt; &lt;div data-role="collapsible" data-collapsed="true"&gt; &lt;h3&gt; Sales Engineer Details &lt;/h3&gt; &lt;div data-role="fieldcontain"&gt; &lt;fieldset data-role="controlgroup" data-mini="true"&gt; &lt;label for="textinput6"&gt; Sales Engineer Name &lt;/label&gt; &lt;input name="txtSalesEngName" id="textinput6" placeholder="" value="" type="text" /&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;div data-role="fieldcontain"&gt; &lt;fieldset data-role="controlgroup" data-mini="true"&gt; &lt;label for="textinput7"&gt; Sales Engineer Phone No. &lt;/label&gt; &lt;input name="txtSalesEngPhone" id="textinput7" placeholder="" value="" type="tel" /&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;a data-role="button" data-inline="true" data-rel="back" data-transition="fade" href="#page2"&gt; Proceed &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;div data-role="page" id="page2" data-theme="b"&gt; &lt;div data-role="header"&gt; &lt;h2&gt; Nalco Water Savings Unit &lt;/h2&gt; &lt;/div&gt; &lt;div data-role="content" style="padding: 15px"&gt; &lt;div data-role="navbar" data-iconpos="right"&gt; &lt;ul&gt; &lt;li&gt; &lt;a href="#page1" data-icon="arrow-r" class="ui-btn-active ui-state-persist"&gt; Customer Info &lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#" data-icon="arrow-r"&gt; Additional Details &lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#page3" data-icon="info"&gt; Summary &lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;h2&gt; &lt;b&gt; What additional installation costs have been identified? &lt;/b&gt; &lt;/h2&gt; &lt;fieldset data-role="controlgroup" data-mini="true" &gt; &lt;div class="ui-grid-b" id="gridAddCost"&gt; &lt;div class="ui-block-a"&gt; &lt;h3&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/h3&gt; &lt;/div&gt; &lt;div class="ui-block-b" &gt; &lt;h3&gt;&lt;b&gt;Cost&lt;/b&gt;&lt;/h3&gt; &lt;/div&gt; &lt;div class="ui-block-c" &gt; &lt;/div&gt; &lt;div class="ui-block-a"&gt; &lt;input name="txt1" id="textinput5" placeholder="" value="" type="text" /&gt; &lt;/div&gt; &lt;div class="ui-block-b"&gt; &lt;input name="txt2" id="textinput5" placeholder="" value="" type="text" /&gt; &lt;/div&gt; &lt;div class="ui-block-c" &gt; &lt;/div&gt; &lt;div class="ui-block-a"&gt; &lt;input name="txt3" id="textinput5" placeholder="" value="" type="text" /&gt; &lt;/div&gt; &lt;div class="ui-block-b"&gt; &lt;input name="txt4" id="textinput5" placeholder="" value="" type="text" /&gt; &lt;/div&gt; &lt;div class="ui-block-c" &gt; &lt;/div&gt; &lt;div class="ui-block-a"&gt; &lt;input name="txt5" id="textinput5" placeholder="" value="" type="text" /&gt; &lt;/div&gt; &lt;div class="ui-block-b"&gt; &lt;input name="txt6" id="textinput5" placeholder="" value="" type="text" /&gt; &lt;/div&gt; &lt;div class="ui-block-c" &gt; &lt;/div&gt; &lt;/div&gt; &lt;input id="btnAddDesc" type="button" value="Add installation" /&gt; &lt;/fieldset&gt; &lt;a data-role="button" data-inline="true" data-rel="back" data-transition="fade" href="#page3"&gt; Proceed &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;div data-role="page" id="page3" data-theme="b"&gt; &lt;div data-role="header"&gt; &lt;h2&gt; Nalco Water Savings Unit &lt;/h2&gt; &lt;/div&gt; &lt;div data-role="content" style="padding: 15px"&gt; &lt;div data-role="content"&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="width:60px;height:60px;" id="smallImage" src="a.png" /&gt; &lt;img style="" id="largeImage" src="a.png" /&gt; &lt;/div&gt;&lt;!-- /content --&gt; &lt;div data-role="navbar" data-iconpos="right"&gt; &lt;ul&gt; &lt;li&gt; &lt;a href="#page1" data-icon="arrow-r" class="ui-btn-active ui-state-persist"&gt; Customer Info &lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#page2" data-icon="arrow-r"&gt; Additional Details &lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#" data-icon="info"&gt; Summary &lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;a data-role="button" data-inline="true" data-rel="back" data-transition="fade" href="#page1"&gt; Proceed &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;script&gt; //App custom javascript &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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