简体   繁体   English

navigator.camera.getPicture不打开设备的默认相机应用程序

[英]navigator.camera.getPicture dont opens the device's default camera application

I have a android application but I cant use camera. 我有一个android应用程序,但不能使用相机。 The app always open the gallery. 该应用程序始终会打开图库。 I try set sourceType like Camera.PictureSourceType.CAMERA but dont work... always open gallery... what is wrong? 我尝试将sourceType设置为Camera.PictureSourceType.CAMERA,但不起作用...总是打开图库...怎么了?

Code: 码:

(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:

<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>

Thanks for any help! 谢谢你的帮助!

Work! 工作!

Add mediaType:Camera.MediaType.CAMERA in options. 在选项中添加mediaType:Camera.MediaType.CAMERA

function capturePhoto() {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, sourceType: Camera.PictureSourceType.CAMERA, mediaType: Camera.MediaType.CAMERA });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 navigator.camera.getPicture无法正常工作 - navigator.camera.getPicture not working properly cordova navigator.camera.getPicture 在 android 中不起作用 - cordova navigator.camera.getPicture not working in android navigator.camera.getPicture在android中不起作用 - navigator.camera.getPicture not working in android 画廊错误中的navigator.camera.getPicture错误“无法创建位图” - navigator.camera.getPicture from the gallery error “Unable to create bitmap” PhoneGap navigator.camera.getPicture不触发回调 - PhoneGap navigator.camera.getPicture don't trigger Callback Cordova navigator.camera.getPicture在Android 4.4 KitKat上以意外格式返回FILE_URI - Cordova navigator.camera.getPicture returns FILE_URI in unexpected format on Android 4.4 KitKat from gallery ionic navigator.camera.getPicture不会从PHOTOLIBRARY返回图像 - ionic navigator.camera.getPicture won't return image from PHOTOLIBRARY navigator.camera.getPicture不会调用成功回调 - 离子框架 - cordova - navigator.camera.getPicture doesn’t call success callback - ionic framework - cordova 为什么我不能在Android应用中使用Cordova 2.7.0触发navigator.camera.getPicture? - Why can't I trigger navigator.camera.getPicture using Cordova 2.7.0 in my Android app? 错误:使用navigator.camera.getPicture()时出现“不允许加载本地资源” - Error: “Not allowed to load local resource” when using navigator.camera.getPicture()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM