簡體   English   中英

手機差距HTML5無法打開相機

[英]Phone gap HTML5 unable to open the camera

在config.xml文件中,我添加了

<plugin name="cordova-plugin-camera" /> <plugin name="cordova-plugin-media-capture"/>

在index.html文件中

<script type="text/javascript" charset="utf-8" src="cordova.js"></script> ... <button onclick="capturePhoto();">Capture Photo</button>

然后在Javascript標簽中

    <script>
    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
      alert(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;
    }

    function capturePhoto() {
        alert("I am here");
        navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
        destinationType: Camera.DestinationType.DATA_URL
        });
    }

    function onFail(message) {
        alert('Failed because: ' + message);
    }
</script>

在按鈕上,單擊“我正在這里”,這表示html按鈕正在調用capturePhoto()函數。 而且我沒有收到任何錯誤警報!

但是相機沒有打開!

我正在使用在線https://build.phonegap.com/以獲取apk

我已經堅持了一段時間。

我通過使用spec =“ 2.0”添加了較舊版本的'cordova-plugin-camera'來解決了該問題

<plugin name="cordova-plugin-camera" spec="2.0" />

並且還添加了

<feature name="Camera"> <param name="android-package" value="org.apache.cordova.CameraLauncher" /> </feature>

有誰知道與cli-6.5.0兼容的最新“ cordova-plugin-camera”版本?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM