Ionic Cordova camera plugin error on Android

天涯浪子 提交于 2019-12-24 02:02:40

问题


Cordova version is: 6.3.0

Cordova Android version is: 5.0.0

Camera Plugin version: cordova-plugin-camera 2.2.0 "Camera"

My code works on multiple devices with Android 5.0 and Android 6.0 but it does not working on Android 4.4, Android 4,3 etc.

In Android 4.4 and 4.3 camera plugin triggers both camera and library but it does not get into .then(function(ImageData){..} it goes into error function.

    $scope.gallery = function() {
var options = {
        quality : 80,
        destinationType : Camera.DestinationType.DATA_URL,
        sourceType : Camera.PictureSourceType.PHOTOLIBRARY,
        allowEdit : false,
        encodingType: Camera.EncodingType.JPEG,
        popoverOptions: CameraPopoverOptions,
        targetWidth: 500,
        targetHeight: 500,
        saveToPhotoAlbum: true,
        correctOrientation: true
    };
     $cordovaCamera.getPicture(options).then(function(imageData) {
          console.log('image'); 
          imaged = imageData;

          $scope.statusMessagePhoto = "photo saved ✓";
     }, function(error) {
            console.log(error.message);
       alert(error.message);
     });
};
$scope.savephoto = function(){
    var options = {
        quality : 80,
        destinationType : Camera.DestinationType.DATA_URL,
        sourceType : Camera.PictureSourceType.CAMERA,
        allowEdit : false,
        encodingType: Camera.EncodingType.JPEG,
        popoverOptions: CameraPopoverOptions,
        targetWidth: 500,
        targetHeight: 500,
        saveToPhotoAlbum: true,
        correctOrientation: true
    };
     $cordovaCamera.getPicture(options).then(function(imageData) {

          imaged = imageData;

          $scope.statusMessagePhoto = "photo saved ✓";
     } , function(error) {
            console.log(error.message);
       alert(error.message);
     });
};

When i press savephoto button camera opens, but in console (log) i get the error "undefined" and the alert too, before even save or choose the photo i want.

Have anyone experienced the same error on Android 4.3 or 4.4. I repeat the code works perfect on Android 5.0 and above.


回答1:


SOLVED!

remove this line from config.xml

  <preference name="AndroidLaunchMode" value="singleInstance"/>


来源:https://stackoverflow.com/questions/38878963/ionic-cordova-camera-plugin-error-on-android

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