PhoneGap的(3.0.0)相机的第一次尝试没有成功相机、PhoneGap

2023-09-05 06:22:41 作者:娘娘

有关测试的目的,我抄在的PhoneGap照相机API ,我把对 onPhotoDataSuccess 警报测试时,功能被触发。在第一张照片拍摄的警报将不会显示。然而在第一次尝试后的警报将显示照片保存后。

For testing purposes I copied the full example found on the phonegap camera API and I put an alert on onPhotoDataSuccess to test when the function is fired. On the first photo taken the alert will not show. However after the first attempt the alert will show after the photo is saved.

有什么建议?我会很高兴,如果事情是不明确更具体。

Any advice? I will be happy to be more specific if something is unclear.

我测试了code以下在我的Andr​​oid的Galaxy S3

I tested the code below on my Android Galaxy S3

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

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

    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(imageData) {
      // 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 = "data:image/jpeg;base64," + imageData;
    }

    // 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.DATA_URL });
    }

    // 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);
    }

    </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>

----------更新1 ------------------

---------- UPDATE 1 ------------------

我已经在code另一位测试过它:

I have tested it on another bit of code:

    (function () {
        $scroller = $('.scroller'),

        // Take a picture using the camera or select one from the library
        takePicture = function (e) {
            var options = {
                quality: 45,
                targetWidth: 1000,
                targetHeight: 1000,
                destinationType: Camera.DestinationType.FILE_URI,
                encodingType: Camera.EncodingType.JPEG,
                sourceType: Camera.PictureSourceType.CAMERA
            };

            navigator.camera.getPicture(
                function (imageURI) {
                    console.log(imageURI);
                    alert('test');
                    $scroller.append('<img src="' + imageURI + '"/>');
                },
                function (message) {
                    // We typically get here because the use canceled the photo operation. Fail silently.
                }, options);

            return false;

        };

    $('.camera-btn').on('click', takePicture);

}());

和此具有相同的效果。它什么都不做的第一单元中,但它显示了第二个单元后的图片。我也是刚刚发现,显示后,第二个是捕捉画面,我拿了第一张照片。看来,在Getpicture中第一个参数不上的第一个捕捉触发。这是令人沮丧的logcat中并没有真正给我任何的工作。

And this has the same effect. It does nothing during the first snap but it shows the picture after the second snap. I also just found out that the picture that shows after the second is snap is the first photo that I took. It seems that the first argument in getPicture does not trigger on the first snap. This is frustrating as logcat does not really show me anything to work with.

----------------更新2 ----------------

---------------- UPDATE 2 ----------------

我只是想它的PhoneGap构建和它的作品。因此,它必须有事情做与插件...

I just tried it on Phonegap Build and it works. So it must have something to do with the plugin...

推荐答案

我有同样的问题更新3.0.0到3.1.0之后。延迟的摄像头,没有地理位置等。

I had the same problem after updating from 3.0.0 to 3.1.0. Delayed camera, no geolocation, etc.

看如果文件平台\机器人\科尔多瓦\版本美国旧版本。 然后,你需要更新你的平台。因此,这里是我做过什么。

Look if the file platforms\android\cordova\version states an old version. Then you need to update your platform. So here is what i did.

删除所有插件:科尔多瓦插件RM org.apache.cordova.camera 删除平台:科尔多瓦平台去除机器人(将删除您已经更改为* .java文件) 添加平台:科尔多瓦平台添加的android 添加的所有插件:科尔多瓦插件添加org.apache.cordova.camera 检查权限 构建它 Remove all plugins: cordova plugin rm org.apache.cordova.camera Remove the platform: cordova platform remove android (will delete changes you have made to *.java files) Add the platform: cordova platform add android Add all plugins: cordova plugin add org.apache.cordova.camera Check permissions Build it

这基本上就像创建一个新的项目。

It's basically like creating a new project.