问题
I've created an Ionic app and I need the camera functionality so that a user can take a picture and send it to a webservice. I've followed the following guide by Ionic.
Basically you just cd
into your applicatoin
cd myApp
then you run
cordova plugin add org.apache.cordova.camera
and once the plugin has been installed, you can invoke it's functionality where ever in your app (because according to Cordova, navigator.camera
is a global object). In my case I'm just doing it in one of my controllers where the following function gets called after a button click using ng-click
:
$scope.takePhoto = function() {
navigator.camera.getPicture(function(imageURI) {
// imageURI is the URL of the image that we can use for
// an <img> element or backgroundImage.
}, function(err) {
// Ruh-roh, something bad happened
}, cameraOptions);
}
But it does nothing.. Now I've followed what Ionic said I must do to a 'T' and nothing more. Is there anything else I should be doing? Editing the config.xml
perhaps? It's probably worth mentioning that this is the first time I've attempted in using a Cordova plugin of any sort.
回答1:
I just resolved this problem by using below code,
$scope.takePhoto = function() {
navigator.camera.getPicture(onSuccess, onFail, {
quality: 75,
targetWidth: 320,
targetHeight: 320,
destinationType: 0
});
function onSuccess(imageData) {
alert('onSuccess');
console.log("data:image/jpeg;base64,"+imageData);
}
function onFail(message) {
alert('Failed because: ' + message);
}
};
The imageData is the src of your captured image
来源:https://stackoverflow.com/questions/32226318/cordova-camera-plugin-not-launching-camera