Bom dia!
Estou tentando implementar o plugin da camera(cordova-plugin-camera) em um App que estou desenvolvendo, porem não consigo fazer o App abrir a câmera. simplesmente não abre nada ao clicar no botão.
Código fonte do JS:
var app = {
// Application Constructor
initialize: function() {
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
},
// deviceready Event Handler
//
// Bind any cordova events here. Common events are:
// 'pause', 'resume', etc.
onDeviceReady: function() {
this.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
console.log('Received Event: ' + id);
},
capturePhoto: function() {
alert('clicou em bater foto!');
navigator.camera.getPicture(onSuccess, onFail, {
quality: 50,
destinationType: Camera.DestinationType.DATA_URL,
allowEdit: true,
sourceType: 1, // 0:Photo Library, 1=Camera, 2=Saved Album
encodingType: 0 // 0=JPG 1=PNG
});
},
onSuccess: function(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData;
alert('success');
},
onFail: function(message) {
alert('Fail: ' + message);
}
};
Código que chama o método que deveria abrir a câmera:
<!DOCTYPE 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">
<link rel="stylesheet" href="icons/material.css">
<link rel="stylesheet" href="css/materialize.min.css">
<link rel="stylesheet" href="css/app.css">
<script type="text/javascript" src="cordova.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/index.js"></script>
<title>Uniodonto Maceió</title>
</head>
<body>
<div class="card">
<div class="card-image">
<div class="cartao-index z-depth-2">
<div> <span class="numero-card-index"></span></div>
</div>
<span class="card-title"></span>
</div>
<div class="card-content">
<button onclick="app.capturePhoto();">Tirar Foto</button> <br>
<img style="display:none;width:60px;height:60px;" id="myImage" src="" />
</div>
</div>
<script src="js/materialize.min.js"></script>
<script src="js/jquery.mask.min.js"></script>
<script src="js/app.js"></script>
<script type="application/javascript">
app.initialize();
</script>
</body>
</html>
Arquivo Config.xml:
<?xml version='1.0' encoding='utf-8'?>
<widget id="br.com.uniodontomaceio.appuniod" version="1.3.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>App Uniodonto Maceió</name>
<description>
Aplicativo da Uniodonto Maceió para controle de informações do plano odontologico.
</description>
<author email="juceliofeitoza@uniodontomaceio.com.br" href="https://www.uniodontomaceio.com.br">
Jucelio Feitoza
</author>
<content src="index.html" />
<plugin name="cordova-plugin-whitelist" spec="1" />
<plugin name="Camera" value="org.apache.cordova.CameraLauncher" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
</widget>
Alguém pode me ajudar a identificar o motivo?