我正在使用phonegap cordova 3.5.1 for android使用Eclipse.i使用下面的代码打开相机但它没有打开。因为它只是升级相同的代码在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" />
答案 0 :(得分:0)
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);
}
答案 1 :(得分:0)
我通过再次下载所需的正确插件并添加android:targetSdkVersion =&#34; 19&#34;解决了这个问题。在manifest.xml中,我已经添加了。现在它工作正常。