7 Replies Latest reply on Apr 17, 2017 7:41 PM by howard_owens

    Camera undefined

    howard_owens

      Here's my javascript

       

      document.addEventListener("deviceready", onDeviceReady, false);

      function onDeviceReady() {

          console.log(navigator.camera);

      }

       

      In my config.xml

       

      <plugin name="cordova-plugin-camera" />
      <feature name="Camera">
         <param name="ios-package" value="CDVCamera" />
      </feature>

          

      there's no errors after the build.

       

      The build shows the plugin being included in the list.

       

      Yet, on console.log(navigator.camera) I get "undefined"

       

      Why?

        • 1. Re: Camera undefined
          howard_owens Level 1

          Ok, by using sample code from this page

           

          PhoneGap API Documentation

           

          I'm able to interact with the camera on my device through the desktop phonegap tool.

           

          However, I get multiple errors with the same code when going through phonegap build.

           

          Typical: TypeError: undefined is not an object (evaluating 'navigator.camera.getPicture')

           

          Why?

          • 2. Re: Camera undefined
            ryanskihead Adobe Employee

            Are you including cordova.js (or phonegap.js) in your html file?

             

            Are you waiting for the deviceready event before calling?

             

            Edit: cancel that, I see that you are waiting for deviceready, and if thats firing you must be including cordova.js.

            • 3. Re: Camera undefined
              ryanskihead Adobe Employee

              Not the cause of the problem, but note that at the top of the documentation page that you just linked, it indicates that you are viewing deprecated docs, and tells you the updated docs location.

              • 4. Re: Camera undefined
                ryanskihead Adobe Employee

                I see that you're using Hydration. I'm guessing you added the camera plugin to your app, and then updated it using Hydration. When you add plugins to your app, you need to do a full rebuild and re-install of the app. Hydration only updates web assets, it cannot update native code such as plugins.

                • 5. Re: Camera undefined
                  howard_owens Level 1

                  By "full rebuild" I assume you mean clicking the rebuild button next to the "update code" button.

                   

                  I did that.

                   

                  Before doing that, I removed the directories for plugins, platforms, and hooks.

                   

                  Same error persists

                   

                  TypeError: undefined is not an object (evaluating 'navigator.camera.getPicture')

                  1 person found this helpful
                  • 6. Re: Camera undefined
                    ryanskihead Adobe Employee

                    And you fully uninstalled and re-installed the app from your device? I just installed your app, and launched test.html, and the camera buttons work as expected. In addition, connecting the chrome inspector, I can call navigator.camera.getPicture successfully.

                    • 7. Re: Camera undefined
                      howard_owens Level 1

                      Thanks ... if that's in instructions somewhere, I missed it.

                       

                      I had not seen anything about uninstalling and reinstalling.  I was just quitting (swipe up) and restarting.

                       

                      Yes, uninstall and reinstall works.  Camera works.