Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 3
Message 1 of 2

Phonegap.build camera not working. What am I missing here?

Hi guys,

 

For a school project I have to make an app in phonegap.build but I'm really struggling to say the least. One of the things I need to implement is the camera. It doesnt have to save the picture or anything, just activate the camera. I have followed the following tutorial which is in Dutch and rather old but I have looked at different forums and found stuff like this. I have tried quite a lot of solutions now but nothing seems to work. I also tried to read the documentation on the plugin as well but it is hard to understand. I don't have basic knowledge of javascript and it is not part of my schools curriculum. Obviously I must be doing something wrong, but I don't know what. At the moment I just got a screen with a button and when I press it, nothing seems to happen. Please help me out. You'll find the code below:

Map structure:

  • index.html
  • config.xml
  • css
    • index.css
  • js
    • index.js

index.js

(function()
{

    document.addEventListener('deviceready', onDeviceReady, false);
 

    function onDeviceReady()
    {

    }
 

    function cameraSuccess(imageData)
    {

        $('#maak-foto').after('<img src="' + "data&colon;image/jpeg;base64," + imageData + '">');
    }
 

    function cameraError(message)
    {

        alert('Er ging iets fout! ' + message);
    }
 

    $('#maak-foto').click(function()
    {
 
        $('img').remove();
 

        navigator.camera.getPicture( cameraSuccess, cameraError, {
            quality: 50, // Foto kwaliteit
            destinationType: Camera.DestinationType.DATA_URL // Base64 gecodeerde afbeelding als resultaat
        });
    });
 

})();


index.html

<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title>Foto maken</title>
    </head>
    <body>
        <div class="app">
            <h1>Foto!</h1>
            <button id="maak-foto">Maken</button>
        </div>
        <script type="text/javascript" src="phonegap.js"></script>
        <script type="text/javascript" src="js/jquery.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
    </body>
</html>

 config.xml:

<widget xmlns     = "<a href="http://www.w3.org/ns/widgets" target="_blank">http://www.w3.org/ns/widgets</a>"
        xmlns:gap = "<a href="http://phonegap.com/ns/1.0" target="_blank">http://phonegap.com/ns/1.0</a>"
        id        = "com.phonegap.hello-world"
        version   = "1.0.0">

    <name>Camera App</name>

    <description>
        Camera example app.
    </description>

    <author href="<a href="http://phonegap.com" target="_blank">http://phonegap.com</a>" email="support@phonegap.com">
        PhoneGap Team
    </author>
    <feature name="<a href="http://api.phonegap.com/1.0/camera"/" target="_blank">http://api.phonegap.com/1.0/camera"/</a>>



    <plugin name="cordova-plugin-camera" source="npm"/>
</widget>
1 Reply
Copilot Lvl 3
Message 2 of 2

Re: Phonegap.build camera not working. What am I missing here?

It gives the following error in chrome: Failed to load resource: the server responded with a status of 404 (Not Found). And its talking about the phonegap.js here. I see that in my first try I forgot to put in the jquery. After I put it in, it won't install on my phone. I just get a message with: App not installed.