0

I have build one worklight application in Worklight v6 which uses cordova API version 2.6

I used the sample provided at this location http://docs.phonegap.com/en/2.6.0/cordova_camera_camera.md.html#Camera

navigator.camera.getPicture(OnSuccess,OnFail, {quality:50,destinationType:Camera.DestinationType.NATIVE_URI,sourceType:Camera.PictureSourceType.CAMERA,saveToPhotoAlbum:true});

Even when I am using NATIVE_URI result I am getting in OnSuccess method is file:// uri instead of content://uri as written on documentation.

Camera.DestinationType = {
DATA_URL : 0,                // Return image as base64 encoded string
FILE_URI : 1,                // Return image file URI
NATIVE_URI : 2               // Return image native URI (eg. assets-library:// on iOS   or content:// on Android)

};

I have added all required permission in menifest xml file.

    <uses-permission android:name="android.permission.CAMERA"/>  
    <uses-feature android:name="android.hardware.camera"/>

see the full code here:

<!DOCTYPE HTML>
<html>
        <head>
            <meta charset="UTF-8">
            <title>testProject</title>
            <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
            <link rel="shortcut icon" href="images/favicon.png">
            <link rel="apple-touch-icon" href="images/apple-touch-icon.png">
            <link rel="stylesheet" href="css/testProject.css">
            <script>window.$ = window.jQuery = WLJQ;</script>
                <script type="text/javascript" charset="utf-8">

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

    // Wait for Cordova to connect with the device
    //
    document.addEventListener("deviceready",onDeviceReady,false);

    // Cordova is ready to be used!
    //
    function onDeviceReady() {
        pictureSource=navigator.camera.PictureSourceType;
        destinationType=navigator.camera.DestinationType;
    }


    // Called when a photo is successfully retrieved
    //
    function onPhotoURISuccess(imageURI) {
      // Uncomment to view the image file URI 
      alert(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 getPhoto(source) {
      // Retrieve image file location from specified source
      navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, 
        destinationType: destinationType.FILE_URI,
        sourceType: source,saveToPhotoAlbum:true });
    }

  function getPhoto2(source) {
      // Retrieve image file location from specified source
      navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, 
        destinationType: destinationType.NATIVE_URI,
        sourceType: source,saveToPhotoAlbum:true });
    }
    // Called if something bad happens.
    // 
    function onFail(message) {
      alert('Failed because: ' + message);
    }

    </script>

        </head>
        <body id="content" style="display: none;">

        <button onclick="getPhoto(pictureSource.CAMERA);">Camera</button><br>
        <button onclick="getPhoto2(pictureSource.CAMERA);">From Photo Album</button><br>
        <img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
        <img style="display:none;" id="largeImage" src="" />


            <!--application UI goes here-->
            testProject
            <script src="js/initOptions.js"></script>
            <script src="js/testProject.js"></script>
            <script src="js/messages.js"></script>
        </body>
</html>
R_Dhorawat
  • 141
  • 1
  • 1
  • 9

1 Answers1

0

I am not sure at the moment why Cordova will return FILE_URI despite setting NATIVE_URI, however do note that it is encouraged to use FILE_URI anyway:

http://docs.phonegap.com/en/2.6.0/cordova_camera_camera.md.html#camera.getPicture

Note: The image quality of pictures taken using the camera on newer devices is quite good, and images from the Photo Album will not be downscaled to a lower quality, even if a quality parameter is specified. Encoding such images using Base64 has caused memory issues on many newer devices. Therefore, using FILE_URI as the 'Camera.destinationType' is highly recommended.


If you insist on using the content:// schema, maybe this following will help: Get content uri from file path in android

Community
  • 1
  • 1
Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • I did read about this note in documentaion site but file:// uri and content:// uri are both are url and it won't cause the issue which mentioned here in my case.In my project to show image which I just clicked with the camera , I need a content://uri as file://uri will give cros domain issue. – R_Dhorawat Aug 26 '13 at 09:33
  • I have gone through the link you pasted but it's seems those solution are having native code. I just want to use the cordvoa API to get the content://uri in my js code itself. And as per documentation It does provide the same when we use NATIVE_URI in options parameter . – R_Dhorawat Aug 26 '13 at 09:44