Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReferenceError: Camera Is Not Defined

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>
like image 551
The Duke Of Marshall שלום Avatar asked Sep 26 '14 20:09

The Duke Of Marshall שלום


1 Answers

I had the same problem I solved it on three steps

The javascript include

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

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

Installing the plugin(s)

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

cordova plugin add org.apache.cordova.camera

Use right android-package

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 :)

like image 76
Shady Mohamed Sherif Avatar answered Oct 21 '22 18:10

Shady Mohamed Sherif