【问题标题】:Ionic cordova-plugin-camera big issue on AndroidAndroid上的离子cordova-plugin-camera大问题
【发布时间】:2016-11-15 14:24:19
【问题描述】:

在 ionic 应用程序中,我想拍照,然后在图像中显示。

$scope.takePicture = function () {
                var options = {
                    quality: 50,

                    destinationType: Camera.DestinationType.FILE_URI,
                    sourceType: Camera.PictureSourceType.CAMERA,
                    allowEdit: false,
                    encodingType: Camera.EncodingType.JPEG,
                    targetWidth: 640,
                    targetHeight: 640,
                    mediaType: Camera.MediaType.PICTURE,
                    saveToPhotoAlbum: false,
                    correctOrientation:true
                };

                $cordovaCamera.getPicture(options).then(function (imageData) {

                var image = document.getElementById('myImage');
                image.src = imageData;
})
}

在 ios 上一切正常,在我的应用中,我看到了图片

在 Android 上,我什么也没看到!但是图像已正确保存,因为我可以毫无问题地在我的服务器中发送图像文件。

我尝试添加:

<allow-navigation href="file:*"/>

在我的 config.xml 中,我添加:

<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src  'self' 'unsafe-inline' *; img-src 'self' data: file: *"> 

在我的 index.html 中,考虑 'file:' 下的图像安全

但是,再一次,没有结果。

有什么帮助吗????

马西莫

【问题讨论】:

    标签: android ionic-framework camera


    【解决方案1】:

    试试这个...

    if (ionic.Platform.isAndroid() && (imageData.indexOf("file://") === -1)) {
       image.src = "file://" + imageData
    } else {
       image.src = imageData
    }
    

    【讨论】:

      【解决方案2】:

      试试下面的,

      $cordovaCamera.getPicture(options).then(function (imageData) 
      {
         var data  = imageData;
         var image = document.getElementById('myImage');
         image.src = data.split('?')[0];
      })
      

      【讨论】:

        猜你喜欢
        • 2018-06-18
        • 2019-02-28
        • 1970-01-01
        • 2018-04-27
        • 1970-01-01
        • 1970-01-01
        • 2018-06-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多