[英]Phone gap HTML5 unable to open the camera
In the config.xml file I've added 在config.xml文件中,我添加了
<plugin name="cordova-plugin-camera" /> <plugin name="cordova-plugin-media-capture"/>
In the index.html file 在index.html文件中
<script type="text/javascript" charset="utf-8" src="cordova.js"></script> ... <button onclick="capturePhoto();">Capture Photo</button>
Then in the Javascript tag 然后在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>
On the button click I am getting the alert 'I am here' which mean the html button is calling the capturePhoto() function. 在按钮上,单击“我正在这里”,这表示html按钮正在调用capturePhoto()函数。 And I am not getting any error alert! 而且我没有收到任何错误警报!
But the camera is not opening! 但是相机没有打开!
I am using the online https://build.phonegap.com/ in order to get the apk 我正在使用在线https://build.phonegap.com/以获取apk
I've been stuck on this for a while.. any advice please ? 我已经坚持了一段时间。
I solved it by adding an older version of 'cordova-plugin-camera' using spec="2.0" 我通过使用spec =“ 2.0”添加了较旧版本的'cordova-plugin-camera'来解决了该问题
<plugin name="cordova-plugin-camera" spec="2.0" />
and also added 并且还添加了
<feature name="Camera"> <param name="android-package" value="org.apache.cordova.CameraLauncher" /> </feature>
Does anyone know what's the latest 'cordova-plugin-camera' version that is compatible with cli-6.5.0 ? 有谁知道与cli-6.5.0兼容的最新“ cordova-plugin-camera”版本?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.