在我添加的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
我被困在这上面有一段时间了..。有什么建议吗?
发布于 2018-10-11 09:43:48
我通过使用spec="2.0“添加一个较旧版本的”cordova插件摄像头“来解决这个问题。
<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兼容的最新的“科多瓦插件-摄像头”版本吗?
https://stackoverflow.com/questions/52753559
复制相似问题