I am trying to access camera from my visualforce page . For that i downloaded cordova library and referenced into my script path . i added camera plugins into my script but still i am unable to access camera using navigator.camera as the value of navigator.camera is always undefined .

<apex:page docType="html-5.0" sidebar="false" 
       showHeader="false" standardStylesheets="false" 
       cache="false" standardController="Merchandise__c"    extensions="MerchandiseMobileController" >

 <html manifest="/apex/MerchandiseMobileCache">

 <title>Merchandise Mobile</title>
 <!-- <apex:includeScript value="{!$Resource.Cordova}"/> -->
 <!-- <apex:includeScript value="{!$Resource.PhoneGap}"/> -->
 <apex:includeScript value="{!URLFOR($Resource.CordovaZip,'cordova-js-master/src/cordova.js')}"/>
 <apex:includeScript value="{!$Resource.Camera}"/>
 <apex:includeScript value="{!$Resource.CameraConstants}"/>
 <apex:includeScript value="{!$Resource.CameraPopoverHandle}"/>
 <apex:includeScript value="{!$Resource.CameraPopoverOptions}"/>
 <apex:stylesheet value="{!URLFOR($Resource.jQueryMobile101, 'jquery.mobile-1.0.1/jquery.mobile-1.0.1.min.css')}" />
  <apex:includeScript value="{!URLFOR($Resource.jQueryMobile101, 'jquery.mobile-1.0.1/demos/jquery.js')}"/>
 <apex:includeScript value="{!URLFOR($Resource.jQueryMobile101, 'jquery.mobile-1.0.1/jquery.mobile-1.0.1.min.js')}"/>
   <apex:stylesheet value="{!URLFOR($Resource.SwipeRightCSS)}" />
<apex:includeScript value="{!URLFOR($Resource.BarCodeScanner)}"/>
<apex:includeScript value="{!$Resource.SFHybridApp}"/>
<apex:includeScript value="{!$Resource.SFSmartStorePlugin}"/>
<!-- This is the JavaScript toolkit that enables REST API calls from a VF page
We'll use this toolkit to implement the 'swipe-right-to-delete' functionality -->
<apex:includeScript value="{!URLFOR($Resource.ForceTK)}"/>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-   scalable=no" />
   <div data-role="page" data-theme="b" id="detailpage">
        <div id="rightPanel">
           <a onClick="takePic();" href="#" data-theme="a" data-iconpos="top" id="picBtn" data-role="button">Take Picture</a>
  <script type="text/javascript">
var merchansideRecs = new Array();
var $j = jQuery.noConflict(); 
var restAPIClient = new forcetk.Client();
$j(document).ready(function() {
    if (!navigator.onLine) {
function isPhoneGap() {
  return /ios|iphone|ipod|ipad|android/i.test(navigator.userAgent);
//Using PhoneGap JS functions to access device features like the Camera                    
  function takePic() {    
    navigator.camera.getPicture(onPicSuccess, onPicFail, { quality: 50}); 
function onPicSuccess(imageData) {
 function onPicFail(message) {
    console.log("Pic failed: " + JSON.stringify(message));

navigator.camera is always returning as undefined could any help me out.

Errors found in console

Uncaught ReferenceError: require is not defined cordova.js:23 Uncaught ReferenceError: require is not defined Camera:22 Uncaught TypeError: Cannot read property 'define' of undefined CameraConstants:21 Uncaught TypeError: Cannot read property 'define' of undefined CameraPopoverHandle:21 Uncaught TypeError: Cannot read property 'define' of undefined CameraPopoverOptions:21 Uncaught ReferenceError: PhoneGap is not defined BarCodeScanner:57 Uncaught TypeError: Cannot read property 'define' of undefined SFHybridApp:9 Uncaught TypeError: Cannot read property 'define' of undefined SFSmartStorePlugin:27

  • did u resolve this issue. I am also facing same issue. – user16267 Jan 9 '15 at 6:40
  • @Pankaj Not yet resolved ! Please lemme know if you found any possiblity to do that – Salesforce developer Jan 12 '15 at 5:03
  • Any luck with this? I have similar issue. navigator.camera is undifined – user25203 Oct 5 '15 at 7:24
  • @Ramya No , not resolved – Salesforce developer Oct 5 '15 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.