I am trying to develop a PhoneGap
application which uses the camera feature. I am following the plugin documentation at https://build.phonegap.com/plugins/768, but with no luck. Everytime I try to use the feature I get the error "ReferenceError: Camera is not defined" when I build and test on my Android device.
Here 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 I'm using to use the camera feature:
<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 am using PhoneGap Build
, here is the config.xml tags I am using:
<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>
I had the same problem I solved it on three steps
I used cordova.js ONLY and removed any phonegap.js
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
You must install the camera plugin using command line; xml only doesn't work
cordova plugin add org.apache.cordova.camera
The package that you are using is org.apache.cordova.CameraLauncher
it is wrong and will give you NullPointer exception.
The right package could be included like that
<feature name="Camera">
<param name="ios-package" value="CDVCamera" />
<param name="android-package" value="org.apache.cordova.camera.CameraLauncher" />
</feature>
Give them a try! Thanks :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With