Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Phonegap - camera not working in Android

Hi Team,
Why i am getting Camera Object or Camera.GetPicture Object return as Undefined for Android Mobile using PhoneGap?

Please advice, if i am missing any reference to be added in application.
1 person has
this question
+1
Reply
  • Amir (Official Rep) August 06, 2012 13:26
    Hi Sh

    Did the deviceready event fires?

    -Amir
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated happy, confident, thankful, excited

  • This reply was removed on 2012-08-08.
    see the change log
  • Yes Amir,this my code...

    <!DOCTYPE html>
    <html>
    <head>
    <title>Capture Photo</title>

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

    var pictureSource; // picture source
    var destinationType; // sets the format of returned value

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

    function onDeviceReady() {
    alert("Event Fired");
    pictureSource = navigator.camera.PictureSourceType;
    destinationType = navigator.camera.DestinationType;
    }

    function onPhotoDataSuccess(imageData) {

    var smallImage = document.getElementById('smallImage');

    smallImage.src = "data:image/jpeg;base64," + imageData;
    }

    function onPhotoURISuccess(imageURI) {

    var largeImage = document.getElementById('largeImage');
    largeImage.style.display = 'block';
    largeImage.src = imageURI;
    }

    function capturePhoto() {

    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
    destinationType: destinationType.DATA_URL
    });
    }

    function capturePhotoEdit() {

    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
    destinationType: destinationType.DATA_URL
    });
    }

    function getPhoto(source) {

    navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
    destinationType: destinationType.FILE_URI,
    sourceType: source
    });
    }

    function onFail(message) {
    alert('Failed because: ' + message);
    }

    </script>
    </head>
    <body>
    <button onclick="capturePhoto();">Capture Photo</button> <br>
    <button onclick="capturePhotoEdit();">Capture Editable Photo</button> <br>
    <button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
    <button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br>
    <img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
    <img style="display:none;" id="largeImage" src="" />
    </body>
    </html>
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated happy, confident, thankful, excited