phonegap我向相机的手机屏幕投降

时间:2014-02-07 16:00:32

标签: javascript android cordova phonegap-plugins

我创建了一个带有phonegap的新项目,以利用相机,但未能让他让我拍照

我已经完成了所有http://docs.phonegap.com/es/3.1.0/cordova_camera_camera.md.html#C%C3%A1mara

但是当我失败时,我没有得到任何错误。什么都不做

我的代码

<!DOCTYPE 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" />

        <title>Hello World</title>
    </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>

和这个脚本

var pictureSource;  
    var destinationType;


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


    function onDeviceReady() {
        pictureSource=navigator.camera.PictureSourceType;
        destinationType=navigator.camera.DestinationType;
    }


    function onPhotoDataSuccess(imageData) {

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


      smallImage.style.display = 'block';



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



    function onPhotoURISuccess(imageURI) {

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


      largeImage.style.display = 'block';


      largeImage.src = imageURI;
    }


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

我已经在manifest.xml的config.xml中获得了许可,我添加了平台,但没有做任何事情。 救命。非常感谢你

1 个答案:

答案 0 :(得分:0)

你确定你安装了这个插件吗?

你说你没有错误,它是否包含logcat?

在你的html中,我看不到包含cordova.js和你的js文件。