problem plugin camera cordova android

0

I'm trying to make a "Hello World" in Cordova, it's a screen with a button that activates the camera, it is not necessary to do anything else, just turn on the camera. the steps I followed.

  • cordova create hello com.bruno.hello hello
  • cd hello
  • cordova plataforms add android
  • cordova build
  • npm install cordova-plugin-camera
  • I edited index.html as shown below
  •  <script type="text/javascript">
        function teste(){
           navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
               destinationType: Camera.DestinationType.DATA_URL
           });             
         }
         function onSuccess(imageData) {
           var image = document.getElementById('myImage');
            image.src = "data:image/jpeg;base64," + imageData;
           }
          function onFail(message) {
             alert('Failed because: ' + message);
          }
     </script>
      <button onclick="teste(); ">TESTAR</button>
    
  • cordova run android
  • The emulator is loaded with the button, but when I press, nothing happens

    I tried to follow the example of the link link

    unsuccessful

      

    I'm using Windows 10 64bit

        
    asked by anonymous 03.12.2015 / 01:15

    2 answers

    1

    Instead of using the Camera.DestinationType.DATA_URL parameter, use Camera.DestinationType.FILE_URI for known memory problems. so it would look like this:

    function onSuccess(uriSrc) {
       var image = document.getElementById('myImage');
       image.src = uriSrc;
    }
        
    16.12.2015 / 12:04
    0

    If you are using the latest version of Cordova, check index.html for the following line:

    <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; media-src  *">
    

    This feature was introduced in the latest versions, and is intended to prevent unwanted access to your application. I had this same problem, and when I deleted the line it worked normally.

    This link has a better description on the subject: link

        
    06.12.2015 / 15:14