Cordova相机应用程序未启动

时间:2017-12-06 13:32:50

标签: cordova cordova-plugins

我一直试图找出为什么在单击图像时相机无法启动,这使得它成为一个按钮。即使尝试重新安装cordova相机插件,错误仍然存​​在。请帮助......

function onDeviceReady() { <<<------ JS File 
        $("#photo1").click(Camera1);
        detection();
    }
    function Camera1() {
        navigator.camera.getPicture(onSuccess, onFail, {
            quality: 50,
            destinationType: Camera.DestinationType.DATA_URL,
            sourceType: Camera.PictureSourceType.CAMERA,
            encodingType: Camera.EncodingType.JPEG,
            targetWidth: 300,
            targetHeight: 300,
            popoverOptions: CameraPopoverOptions,
            saveToPhotoAlbum: true
        });
        function onSuccess(imageData) {
            var image = document.getElementById('myImage');
            image.src = "data:image/jpeg;base64," + imageData;
        }
        function onFail(message) {
            $("#errormsg").text("ERROR");
        }
    };

        });
<body> <<<----- HTML File  
    <div data-role="page" id="page1">
        <input type="image" id="photo1" src="images/download.png" width="200" height="90" />
        <label for="photo2">Take a Photo</label>
        <img id="myImage" src="" />
        <div id="errormsg"></div>
        <div id="displayresults"></div>
        <input type="image" id="fall" src="images/piq96Mxi9-800x675.jpg" width="200" height="90" />
        <label for="photo3">Fall Detection</label>
    </div>

    <div data-role="page" id="page2">
     <p id="lastphoto"></p>
        <button class="ui-btn">Send</button>
    </div>




    <script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="scripts/platformOverrides.js"></script>
    <script type="text/javascript" src="scripts/index.js"></script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

可能的解决方案是,

  1. 离线下载JQuery,而不是在CDN上加载(由于加载时间不正确,可能会发生错误)
  2. 确保您正在验证JQuery ready +设备就绪事件
  3. 检查您的相机访问权限