在我添加的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
我已经坚持了一段时间..有什么建议吗?
答案 0 :(得分:0)
我通过使用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”版本是什么吗?