0
我有一個Android應用程序,但我不能使用相機。 該應用程序總是打開畫廊。 我嘗試設置sourceType像Camera.PictureSourceType.CAMERA但不工作...總是打開畫廊...有什麼不對?navigator.camera.getPicture不打開設備的默認相機應用程序
代碼:
(function() {
document.addEventListener('deviceready', onDeviceReady.bind(this), false);
function onDeviceReady() {
var buttonTakePhoto = document.querySelector("#btnTakePhoto");
if (buttonTakePhoto != null) {
buttonTakePhoto.addEventListener("click", capturePhoto, false);
}
};
function capturePhoto() {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, sourceType: Camera.PictureSourceType.CAMERA });
};
//Callback function when the picture has been successfully taken
function onPhotoDataSuccess(imageData) {
var smallImage = document.getElementById('smallImage');
// Unhide image elements
smallImage.style.display = 'block';
smallImage.src = imageData;
};
//Callback function when the picture has not been successfully taken
function onFail(message) {
alert('Failed to load picture because: ' + message);
};
HTML:
<html>
<head>
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
</head>
<body>
<input type="button" value="Tirar Foto" id="btnTakePhoto" class="quitButton" />
<img id="smallImage"/>
<script type="text/javascript" src="scripts/takePhoto.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="scripts/platformOverrides.js"></script>
<script type="text/javascript" src="scripts/index.js"></script>
</body>
</html>
感謝您的幫助!