【问题标题】:camera not getting opened in cordova 3.5.1相机没有在科尔多瓦 3.5.1 中打开
【发布时间】:2015-10-01 17:19:05
【问题描述】:

我正在使用 Eclipse 为 android 使用 phonegap cordova 3.5.1。我使用下面的代码打开相机但它没有打开。因为它只是升级相同的代码在 cordova 2.9.0 中工作正常但在 3.5.1 中没有.我已经使用了所需的插件并在 config.xml 和 manifest.xml 中获得了许可,即使它无法正常工作。我是 android 和 cordova 的新手,任何帮助表示赞赏

function onPhotoFileSuccess(imageData) {
                    $('#idDelImgPhotoImg').append('<div class="mainPhotodiv"><div class="deleteImg"><img id="ImgIdDelete" src="images/delete.png" alt="" onclick="deleteImg(this)" style="width: 100%" /></div> <div class="photodiv" id="idPhotoDiv"><img src="' + imageData + '" alt="" style="width: 100%;height:50%" id="LocPhotoImag" /></div></div>');

                    $('#idAddPhotoImg').show();
                    Locphotos.push(imageData);
                    $('#idAddanotherphotoImg').hide();
                    if ($('#idDelImgPhotoImg').html().trim()) {
                        $('#idAddPhotoImg').hide();
                        $('#idAddanotherphotoImg').show();


                    }

                    else {

                        $('#idAddanotherphotoImg').hide();
                        $('#idAddPhotoImg').show();
                    }

                }


    function capturePhotoWithFile() {
        navigator.camera.getPicture(onPhotoFileSuccess, onFail, { quality: 50, destinationType: Camera.DestinationType.FILE_URI });

    };

    function onFail(message) {

    }
function deleteImg(ImgTag) {

        $(ImgTag).parents('.mainPhotodiv').remove();
    }

.html

<img src="images/Addphoto.png" style="width: 100%" alt="" onclick="capturePhotoWithFile();"/>
    </div>
    <div id="idDelImgPhotoImg">
        <!--<div class="deleteImg">
            <img src="images/delete.png" alt="" style="width: 100%" /></div>
        <div class="photodiv">
            <img src="images/5mount-img.png" alt="" style="width: 100%" /></div>-->
    </div>
      <div style="margin-top:10px;display:none;" id="idAddanotherphotoImg"> <img src="images/6Addanotherphoto.png" alt="" style="width:100%" onclick="capturePhotoWithFile()"/></div>

       <div id="idVedioShowdiv" style="display:none"></div>
       <div style="margin-top:20px!important;"></div>

congif.xml

 <rim:permissions>
  <rim:permit>read_geolocation</rim:permit>
 </rim:permissions>

 <access subdomains="true" origin="*"  />
 <access origin="http://2.8.2.3:34/Service.asmx" subdomains="true" />
 <access origin="http://8.9.60.6:9/rt.asmx" subdomains="true" />
 <access origin="http://comp.cloud.net:2/rr" subdomains="true" />
 <access origin="http://comp.cloud.net:91/rr" subdomains="true" />
 <access origin="http://comp.cloud.net:93/rr"  subdomains="true" />

 <preference name="phonegap-version" value="3.5.1" />

<gap:plugin name="org.apache.cordova.battery-status" version="0.2.11"/>
<gap:plugin name="org.apache.cordova.camera" version="3.3.0" />
  <gap:plugin name="org.apache.cordova.media-capture" version="0.3.3" />
<gap:plugin name="org.apache.cordova.console" version="0.2.11" />
<gap:plugin name="org.apache.cordova.contacts" version="0.2.13" />
<gap:plugin name="org.apache.cordova.device" version="0.2.12" />
<gap:plugin name="org.apache.cordova.device-motion" version="0.2.10" />
<gap:plugin name="org.apache.cordova.device-orientation" version="0.3.9" />
<gap:plugin name="org.apache.cordova.dialogs"/>
<gap:plugin name="org.apache.cordova.file"  version="1.3.1" />
<gap:plugin name="org.apache.cordova.file-transfer"  version="0.4.6" />
<gap:plugin name="org.apache.cordova.geolocation" version="0.3.10" />
<gap:plugin name="org.apache.cordova.globalization" version="0.3.1" />
<gap:plugin name="org.apache.cordova.inappbrowser" version="0.5.2" />
<gap:plugin name="org.apache.cordova.media" version="0.2.13" />
<gap:plugin name="org.apache.cordova.network-information" version="0.2.12" />
<gap:plugin name="org.apache.cordova.splashscreen" version="0.3.4"  />
<gap:plugin name="org.apache.cordova.vibration" version="0.3.11"  /> 

【问题讨论】:

  • 显示什么错误?
  • @Nehil Mistry 它没有显示错误,在发出警报时它进入功能
  • 您是否检查过相机插件是否在插件列表中? cordova plugin ls
  • @Nehil Mistry 在 www 文件夹内我有一个插件文件夹,其中包含 org.apache.cordova.camera,其中包含 Camera.js、cameraConstants.js、CameraPopoverhandle.js 和 CamerapopoverOptions.js
  • 请分享您的 config.xml

标签: android cordova


【解决方案1】:
navigator.camera.getPicture(onSuccess, onFail, { quality: 20,correctOrientation : true,targetWidth: 700,
  targetHeight: 700,
    destinationType: Camera.DestinationType.DATA_URL
 }); 

    function onSuccess(imageData) {
        image = imageData;

    }

    function onFail(message) {
        alert('Failed because: ' + message);
    }

【讨论】:

  • config.xml 已共享
  • 尝试删除 config.xml 中的版本编号以插入摄像头,并按照我在答案中编辑代码的方式按照函数序列捕获图像。同时尝试删除媒体插件
  • 删除 config.xml 文件中的版本后无法正常工作
【解决方案2】:

我通过再次下载所需的正确插件并在 manifest.xml 中添加 android:targetSdkVersion="19" 解决了这个问题,我已经添加了。现在它工作正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-12
    • 2016-04-05
    • 1970-01-01
    相关资源
    最近更新 更多