2017-07-14 7 views
0

私はアンドロイドアプリケーションを持っていますが、カメラは使用できません。 アプリは常にギャラリーを開きます。 Camera.PictureSourceType.CAMERAのようにsourceTypeを設定しようとしましたが、動作しません...常にギャラリーを開きます...何が間違っていますか?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> 

ありがとう!

答えて

0

Work!

mediaType:Camera.MediaType.CAMERAをオプションで追加します。

function capturePhoto() { 
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, sourceType: Camera.PictureSourceType.CAMERA, mediaType: Camera.MediaType.CAMERA }); 
関連する問題