ReferenceError: camera not defined

I am trying to develop a PhoneGap application that uses the camera function. I follow the plugin documentation at https://build.phonegap.com/plugins/768 but no luck. Every time I try to use this function, I get the error “ReferenceError: Camera is not defined” when creating and testing on my Android device.

This is what the head of my index.html looks like:

 <script type="text/javascript" src="phonegap.js"></script> <script type="text/javascript" src="cordova.js"></script> 

And here is the script that I use to use the camera function:

 <script> function take_picture(){ try{ navigator.camera.getPicture(cameraSuccess, cameraError, { quality: 50, destinationType: Camera.DestinationType.DATA_URL }); }catch(e){ alert(e); } } function cameraSuccess(imageData){ try{ $("#camera_image").attr('src', imageData); }catch(e){ alert(e); } } function cameraError(message){ try{ alert('Failed because: '+message); }catch(e){ alert(e); } } </script> 

And since I use PhoneGap Build , here are the config.xml files that I use:

 <gap:config-file platform="android" parent="/manifest"> <uses-permission name="android.permission.CAMERA" /> </gap:config-file> <feature name="http://api.phonegap.com/1.0/camera"/> <feature name="Camera"> <param name="android-package" value="org.apache.cordova.CameraLauncher" /> <param name="ios-package" value="CDVCamera" /> </feature> 
+5
source share
1 answer

I had the same problem as I solved in three steps

Javascript included

I used cordova.js ONLY and deleted any phonegap.js

  <script type="text/javascript" charset="utf-8" src="cordova.js"></script> 

Install Plugin (s)

You must install the camera plugin using the command line; xml just doesn't work

 cordova plugin add org.apache.cordova.camera 

Use the right android package

The package you use, org.apache.cordova.CameraLauncher incorrect and will give you a NullPointer exception. The correct package may be included as

 <feature name="Camera"> <param name="ios-package" value="CDVCamera" /> <param name="android-package" value="org.apache.cordova.camera.CameraLauncher" /> </feature> 

Give it a try! Thanks:)

+4
source

Source: https://habr.com/ru/post/1203507/


All Articles