Cordova camera plugin not launching camera

杀马特。学长 韩版系。学妹 提交于 2020-01-17 04:11:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!