android Cordova camera plugin problem

Asked

Viewed 660 times

0

I’m trying to make a "Hello World" in Ordova, it’s a screen with a button that triggers the camera, it’s not necessary to do anything else, just trigger the camera. the steps I took.

  1. Cordova create hello com.bruno.hello hello
  2. hello cd
  3. Cordova plataforms add android
  4. Cordova build
  5. npm install Cordova-plugin-camera
  6. I edited the index.html as shown in the section 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>
  1. Cordova run android

The emulator is pressed with the button, but when I press, nothing happens

I tried to follow the example of the link https://cordova.apache.org/docs/en/1.6.1/cordova/camera/camera.getPicture.html

unsuccessful

I’m using Windows 10 64bits

  • A question, have you ever tried to run on a real device? I had problems with Cordova running on the SDK virtual machine. Plug the device, enable USB debugging and have the drivers installed, then run Cordova run android

  • @Renancavalieri tried yes, but with the phonegap Veloper, I do not know if it is the same thing, but ran the app with the same problem

  • In this case then it remains to be seen if you have put permissions for your application, check these files and see if they have the following lines https://cordova.apache.org/docs/en/2.5.0/cordova/camera/camera.html

  • @Renancavalieri this is on Androidmanifest????

  • Yes, although this documentation is outdated, the paths are the same, at least they were until version 4.0 which was the one I used.

  • @Renancavalieri only has uses-permission android:name="android.permission.CAMERA", how do I include this line there? which tag I use?

  • an important detail, you may be using different version documentation to which you are installed, make sure of it. The most recent can be accessed at : https://cordova.apache.org/docs/en/latest/cordova/plugins/pluginapis.html

Show 3 more comments

2 answers

1

Instead of using the parameter Camera.DestinationType.DATA_URL use Camera.DestinationType.FILE_URI for memory problems already known. then I’d be like this:

function onSuccess(uriSrc) {
   var image = document.getElementById('myImage');
   image.src = uriSrc;
}

  • exact, I am starting, and deconhecia the basic structure, after a longer studying I found, thank you very much for the help

  • I’m glad it worked out.

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 has been introduced in the latest versions, and serves to prevent unwanted access to your application. I had this same problem, and when I deleted the line worked normally.

This link has a better description of the subject: http://www.raymondcamden.com/2015/05/25/important-information-about-cordova-5

Browser other questions tagged

You are not signed in. Login or sign up in order to post.