0
votes

I am trying to access the camera of my device from a Web page file using the phonegap. I went through the following steps.

I created the HTML and JavaScript sample files from the following link. http://docs.phonegap.com/en/2.9.0/cordova_camera_camera.md.html#cameraOptions

I downloaded the latest phonegap 2.9.1 and copied the cordova file in my assets/www folder.

I pasted the config.xml file in the res/xml folder.

I included the cordova-2.2.0.jar file into the libs folder.

I am calling the HTML file from my java class.

But it is showing the following error.

03-18 15:19:00.364: E/Web Console(15868): Uncaught TypeError: Cannot read property 'DATA_URL' of undefined:92
03-18 15:19:00.864: V/WebViewInputDispatcher(15868): blockWebkitDraw
03-18 15:19:00.864: V/WebViewInputDispatcher(15868): blockWebkitDraw lockedfalse
03-18 15:19:01.169: D/webview(15868): blockWebkitViewMessage= false
03-18 15:19:01.174: E/Web Console(15868): Uncaught TypeError: Cannot read property 'DATA_URL' of undefined:92

Please help me solving my error.

3

3 Answers

0
votes

try to use the upgrade version. The latest version like phonegap 3.4.0 it will work

0
votes

First of all, i suspect it's not good to use cordova-2.2.0.jar and docs for 2.9.0, isn't it better to user cordova-2.9.0.jar instead? Just to be sure: is camera feature (plugin) included in config.xml?

Also there are some related questions with ideas how to solve something similar: cordova giving TypeError: Cannot read property 'DATA_URL' of undefined:68 Can not read propery 'DATA_URL' of undefined type at file:///android_asset/www/apis/camera.js:45

0
votes

change DATA_URL to FILE_URI IN getPhoto() function

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

    // Wait for device API libraries to load
    //
    document.addEventListener("deviceready",onDeviceReady,false);

    // device APIs are available
    //
    function onDeviceReady() {
        pictureSource=navigator.camera.PictureSourceType;
        destinationType=navigator.camera.DestinationType;
    }

    // Called when a photo is successfully retrieved
    //
    function onPhotoDataSuccess(imageURI) {
      // Uncomment to view the base64-encoded image data
      // console.log(imageData);

      // Get image handle
      //
      var smallImage = document.getElementById('smallImage');

      // Unhide image elements
      //
      smallImage.style.display = 'block';

      // Show the captured photo
      // The inline CSS rules are used to resize the image
      //
      smallImage.src = imageURI;
    }

    // Called when a photo is successfully retrieved
    //
    function onPhotoURISuccess(imageURI) {
      // Uncomment to view the image file URI
      // console.log(imageURI);

      // Get image handle
      //
      var largeImage = document.getElementById('largeImage');

      // Unhide image elements
      //
      largeImage.style.display = 'block';

      // Show the captured photo
      // The inline CSS rules are used to resize the image
      //
      largeImage.src = imageURI;
    }

    // A button will call this function
    //
    function capturePhoto() {
      // Take picture using device camera and retrieve image as base64-encoded string
      navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
        destinationType: destinationType.FILE_URI , saveToPhotoAlbum: true });
    }

    // A button will call this function
    //
    function capturePhotoEdit() {
      // Take picture using device camera, allow edit, and retrieve image as base64-encoded string
      navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
        destinationType: destinationType.DATA_URL });
    }

    // A button will call this function
    //
    function getPhoto(source) {
      // Retrieve image file location from specified source
      navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
        destinationType: destinationType.FILE_URI,
        sourceType: source });
    }

    // Called if something bad happens.
    //
    function onFail(message) {
      alert('Failed because: ' + message);
    }