+ Start a Discussion
Binu 8Binu 8 

Hybrid App- Camera not open

Hi Team,

 I have created a hybrid application which is related to native camera. In my visualforce page I have included cordova.js and that will support
 navigator.camera.getPicture() functionality. But When I am trying to access this function from my android phone showing this error in eclipse console 
"Uncaught TypeError: Cannot read property 'getPicture' of undefined". I think plugins for camera is miising in my hybrid project.Is that correct? If yes How can I add cordova plugins in existing projects?
 Please suggest a better solution to resolve this problem.
Shashi PatowaryShashi Patowary
Hi Binu,

If this is hybrid mobile app, are you using Android or Apple ? I created a hybrid android app using Cordova and set up cordova in the android project itself in eclipse. If you are using android, you can check this blog -

https://www.adobe.com/devnet/archive/html5/articles/getting-started-with-phonegap-in-eclipse-for-android.html
Please let me know if this is helpful
Regards,
Shashi
Binu 8Binu 8
Hi Shashi,

Thanks for your reply. Actually I am using android  salesforce sdk for creating hybrid mobile app. In this blog you mentioned about only phonegap + android. 
But my doubt is related to salesforce sdk.

Please check these step which I follow for create forcedroid project

1. created forcedroid project through node js command prompt
2. import SmartSync, SmartStore, SalesforceSDK, CordovaLib, HybridDemo(My application) projects to eclipse.
3. Set first page as HybridVFPage in bootconfig.json of HybridDemo.
4. In HybridVFPage inluded cordova.js and execute the function navigator.camera.getPicture() from a button click.
5. "Uncaught TypeError: Cannot read property 'getPicture' of undefined". error is showing.

I think some plugin is missing in my project,IS that right?
Shashi PatowaryShashi Patowary
Hi Priya,

It seems that SFDC SDK has updated the version of Cordova (PhoneGap is the eariler version of Cordova) .Anyway you can refer to this page if you haven't already -

https://developer.salesforce.com/docs/atlas.en-us.mobile_sdk.meta/mobile_sdk/hybrid_ios.htm

It's clearly mentioned to not to include Cordova.js

Do not include cordova.js, cordova.force.js, or any Cordova plug-ins.

To be frank, I don't have SFDC SDK installed in my laptop.I tried it in my previous laptop with a older version of Cordova.But it was working fine.

Please let me know if you are still stuck.I will try this at my end.

regards,
Shashi
Binu 8Binu 8
Hi Shashi,

Thanks for your reply. I tried to create with your refference link. The project creation is completed and runs on my android device is fine.
Also I added the pluggins for camera in to my project. I can see org.apache.cordova.camera library in my project. And my first page of the application is "apex/PhonegapPage". The page is located in my salesforce developer edition instance. I think the problem is happening in my visual force page. After runs the application on my android device the visualforce page will show. When click the button for open the camera the same error is occuring."Uncaught TypeError: Cannot read property 'getPicture' of undefined".

 The code of my visual force page is here.Please veryfy and let me know what is the problem,
 
 <apex:page docType="html-5.0" sidebar="false"
           showHeader="false" standardStylesheets="false" 
           cache="false">
    
 <apex:includeScript value="{!URLFOR($Resource.Cordova)}"/>
 
   <script>
    function capturePhotoWithFile() {
        navigator.camera.getPicture(onPhotoFileSuccess, onFail, { quality: 50, destinationType: Camera.DestinationType.FILE_URI });
    }
    function onPhotoFileSuccess(imageData) {
        
    }
    function onFail(imageData) {
        
    }
    </script>
    
    <div class="app">
        <button onclick="capturePhotoWithFile();">Take Picture</button>
    </div>
  
</apex:page>
Binu 8Binu 8
Hi Shashi,

My issue is resolved. The issue was include script problem in visual force. I changed from 
<apex:includeScript value="{!URLFOR($Resource.Cordova)}"/>
to 
 <script src="https://localhost/cordova.js"></script>

Thanks a lot Shashi.Thanks for your help.