20 Replies Latest reply on Apr 26, 2018 3:31 AM by mail@biancagroh.de

    cordova-plugin-camera not working on android device

    mahmoudh83497657

      Hi,

      I am trying to use cordova-plugin-camera in my app, but i didn't work.

      Below the steps i used to add this plugin:

      add <plugin name="cordova-plugin-camera" spec="~4.0.2" /> in my config file.

      add  <script src="cordova.js"></script> in my index.html

      use the he global scoped navigator, after the deviceready event:

      function onDeviceReady() { 

              alert('ready');

              pictureSource = navigator.camera.PictureSourceType;

              alert(pictureSource);

              destinationType = navigator.camera.DestinationType;

          }

      ....

      Can anyone help me plz?

        • 1. Re: cordova-plugin-camera not working on android device
          jcesarmobile_ Adobe Community Professional

          What exactly doesn't work?
          Your code doesn't call getPicture, so you are not really using the camera

          • 2. Re: cordova-plugin-camera not working on android device
            setss50585632

            HI,

            I didn't put all the code here.

            I am calling the below and it is not working:

               document.addEventListener("deviceready", function () {

                        alert('deviceready');

                        navigator.camera.getPicture(onSuccess, onFail, {

                            sourceType: Camera.PictureSourceType.PHOTOLIBRARY,

                            destinationType: Camera.DestinationType.DATA_URL

                        });

                        function onSuccess(imageData) {

                            alert('succsess');

                            var image = document.getElementById('myImage');

                            image.src = "data:image/jpeg;base64," + imageData;

                        }

             

                        function onFail(message) {

                            alert('Failed because: ' + message);

                        }

                    }, false);

            Thank you in advance.

            • 3. Re: cordova-plugin-camera not working on android device
              ralphs26798824 Level 1

              Try this;

               

               document.addEventListener("deviceready", function () {                                       
                   alert('deviceready');                                                                     
                                                                                                            
                   function onSuccess(imageData) {                                                           
                        alert('succsess');                                                                    
                        var image = document.getElementById('myImage');                                       
                        image.src = "data:image/jpeg;base64," + imageData;                                    
                   }                                                                                         
                                                                                                            
                   function onFail(message) {                                                                
                        alert('Failed because: ' + message);                                                  
                   }                                                                                         
                                                                                                             
                                                                                                             
                   if(typeof navigator !== 'undefined' && typeof navigator.camera !== 'undefined') {         
                        alert('calling getPicture');                                                          
                        navigator.camera.getPicture(onSuccess, onFail, {                                      
                             sourceType: Camera.PictureSourceType.PHOTOLIBRARY,                                
                             destinationType: Camera.DestinationType.DATA_URL                                  
                        });                                                                                   
                   } else {                                                                                  
                        alert('no navigator.camera - did you install the plugin?');                                                         
                   }                                                                                         
                                                                                                            
              }, false);                                                                                    

               

              Check your build logs and search for the camera plugin. Your might be using an incompatible plugin version with the phonegap-version. Otherwise post your config and build log here.

              • 4. Re: cordova-plugin-camera not working on android device
                mahmoudh83497657 Level 1

                Hi,

                Thank you for your reply.

                I tried an old versin of the plugin(2.0) and it is working fine.

                I didn't understand why it is not working for the current version(4.0).

                Do you have any idea about this?

                 

                Thank you,

                • 5. Re: cordova-plugin-camera not working on android device
                  ralphs26798824 Level 1

                  As mentioned, this could be due to an incompatibility between your phonegap-version;

                  <preference  name="phonegap-version" value="cli-8.0.0" />
                  

                   

                  And the plugin spec;

                  <plugin name="cordova-plugin-camera" source="npm" />
                  

                   

                  If you check the build logs, search for 'cordova-plugin-camera' you will see if it got installed and if not, the reason why.

                   

                  Cheers

                  2 people found this helpful
                  • 6. Re: cordova-plugin-camera not working on android device
                    jcesarmobile_ Adobe Community Professional

                    Latest camera plugin requires cordova-android 6.3.0 or newer, that is cli 7.1.0 or newer

                    2 people found this helpful
                    • 7. Re: cordova-plugin-camera not working on android device
                      ralphs26798824 Level 1

                      Yes - hence why they need to check these configurations to ensure they're using the right cordova version for the plugin version.

                      • 9. Re: cordova-plugin-camera not working on android device
                        setss50585632 Level 1

                        Thank you !

                        I need to know how i can find the version of the plugin which is compatible with a specific phonegap version.

                        For example what is the version of the plugin if the phonegap version is cli-6.5.0 ?

                         

                        Regards,

                        • 10. Re: cordova-plugin-camera not working on android device
                          jcesarmobile_ Adobe Community Professional

                          I don't think there is such documentation about which platform version matches a plugin version.

                           

                          Best way is checking the plugin package.json, there is a cordovaDependencies section where you can see some restrictions for some plugin versions.


                          In case of camera plugin

                          "3.0.0": {

                                  "cordova-android": ">=6.3.0"    

                          }

                           

                           

                          That means version 3 of the plugin requires cordova-android 6.3.0, that is the version pinned in CLI 7.1.0.
                          So for 6.5.0 you will need an older version than 3.0.0. Looking into the releases, the previous one was 2.4.1

                          1 person found this helpful
                          • 11. Re: cordova-plugin-camera not working on android device
                            mail@biancagroh.de Level 1

                            Thats crap...

                             

                            Fetching plugin "cordova-plugin-camera" via npm

                            Installing "cordova-plugin-camera" at "4.0.3" for android

                            Plugin doesn't support this project's cordova-android version. cordova-android: 6.1.2, failed version requirement: >=6.3.0

                            Skipping 'cordova-plugin-camera' for android

                             

                             

                            cli-6.5.0 is the default today and a month before (beginning  march)

                            the unspecified "cordova-plugin-camera" is working on 6.5.0  !!!!

                             

                            Now i have to go back to 2.4.1 ??  Thats *!#. sorry.

                             

                            The newer cli version don't working on build with the other plugins

                            • 12. Re: cordova-plugin-camera not working on android device
                              jcesarmobile_ Adobe Community Professional

                              Just because it's default doesn't mean you have to use it. Updating to 7.1.0 should not break anything and camera plugin and all others that now require cordova-android >= 6.3.0 will install fine.

                               

                              What is *!# is to pretend to use 15 month old tooling with latest plugins and complain because it doesn't work.

                              • 13. Re: cordova-plugin-camera not working on android device
                                mail@biancagroh.de Level 1

                                yes 7.1.0 ruins everything on phonegap build

                                 

                                and at last build on 25 March it included the latest camera plugin

                                 

                                the 7.1.0 can't build !!

                                 

                                example:

                                Error: Source path does not exist: www/res/screen/android/drawable-land-hdpi.png

                                  at updatePathInternal (/cordova/node_modules/cordova-common/src/FileUpdater.js:145:19)

                                  at /cordova/node_modules/cordova-common/src/FileUpdater.js:223:19

                                  at Array.forEach (native)

                                  at Object.updatePaths (/cordova/node_modules/cordova-common/src/FileUpdater.js:221:33)

                                  at updateSplashes (/cordova/lib/prepare.js:299:17)

                                  at /cordova/lib/prepare.js:50:9

                                  at _fulfilled (/cordova/node_modules/q/q.js:854:54)

                                  at self.promiseDispatch.done (/cordova/node_modules/q/q.js:883:30)

                                  at Promise.promise.promiseDispatch (/cordova/node_modules/q/q.js:816:13)

                                  at /cordova/node_modules/q/q.js:624:44

                                 

                                but all the files exist


                                build broke on ios and android but with 6.5.0 everthing is fine

                                • 14. Re: cordova-plugin-camera not working on android device
                                  jcesarmobile_ Adobe Community Professional

                                  I'm sorry, but the problem is you, not PGB, there was a big change from 6.5.0 to 7.0.1 and you didn't read the blog post where they explained it. On 7.x.x Cordova handle the splash images and icons and you might need to update the paths (in your case you need it for sure). There are a bunch of threads about it.

                                  • 15. Re: cordova-plugin-camera not working on android device
                                    mail@biancagroh.de Level 1

                                    Do you have a link?

                                     

                                    We read the docs not some blogs

                                    • 16. Re: cordova-plugin-camera not working on android device
                                      mail@biancagroh.de Level 1

                                      and that is not funny forcing people to use the newer cli version if the want the camera plugin back

                                      • 17. Re: cordova-plugin-camera not working on android device
                                        jcesarmobile_ Adobe Community Professional

                                        Reading the blog is a good way of knowing what things changed as they announce breaking changes there:
                                        https://blog.phonegap.com/phonegap-7-0-1-now-on-build-and-it-includes-some-important-chang es-89087fe465f5

                                         

                                        Anyway, the docs also mention it:http://docs.phonegap.com/phonegap-build/configuring/icons-and-splash/

                                        As of cli-7.0.1 and the new builder (more info), PhoneGap Build hands off to Cordova put read your icon and splash configurations and put them where they need to be. As a result, we recommend referring to the Cordova Icon and Splashscreen Plugin docs for the most up to date instructions. Otherwise if you're still using cli-6.5.0 (and the old builder), see below.

                                         

                                        Icons and Splash | PhoneGap Docs


                                        Plugins used to have a dependency to a compat plugin to request the permissions, as so much plugins being dependent on the same plugin was causing too much trouble because of some requiring different versions, the compat plugin was integrated into cordova-android 6.3.0, that's why the new versions of the plugins need that. Probably not funny, but definitely needed.

                                        • 18. Re: cordova-plugin-camera not working on android device
                                          mail@biancagroh.de Level 1

                                          i remove all icons and splashscreens. but on

                                          cli-7.1.0

                                           

                                          BUILD FAILED

                                           

                                          Error: /gradlew: Command failed with exit code 1 Error output:

                                          Note: Some input files use or override a deprecated API.

                                           

                                          I can't do without the plugins - so from rain to eaves

                                           

                                          i can use 7.1.0 with camera

                                          or 6.5.0 with the other plugins

                                          • 20. Re: cordova-plugin-camera not working on android device
                                            mail@biancagroh.de Level 1

                                            On cli-6.5.0 i go back now to 2.3.0

                                             

                                            but one problem is that debugging isnt working.

                                             

                                            <gap:plugin name="cordova-plugin-camera" source="npm" spec="2.3.0" />