【问题标题】:Cordova Camera not working when application is build for android为 android 构建应用程序时,Cordova 相机不工作
【发布时间】:2016-07-22 18:28:38
【问题描述】:

我正在为我的 Ionic 应用程序使用相机插件。 当我在设备上尝试浏览器应用程序时,相机可以正常工作,但是当我在设备上构建和运行 APK 时,不会触发 getPicture 方法。

$scope.takePictureBack = function () {
            $ionicPlatform.ready(function () {
                var cameraOptions = {
                    quality: 100,
                    targetHeight: 1080,
                    targetWidth: 1920,
                    destinationType: Camera.DestinationType.DATA_URL
                };
                var success = function (data) {
                    $scope.$apply(function () {
                        /*
                         remember to set the image ng-src in $apply,
                         i tried to set it from outside and it doesn't work.
                         */
                        $scope.cameraPicBack = "data:image/jpeg;base64," + data;
                    });
                };
                var failure = function (message) {
                };
                //call the cordova camera plugin to open the device's camera
                navigator.camera.getPicture(success, failure, cameraOptions);
            })
        };

我尝试过用日志测试,似乎方法的失败回调和成功回调都没有到达。

有谁知道相机插件有什么并发症吗? 作为记录,我的 cordova 和 ionic 已更新,我正在使用 Android 6.0.1 在 Galaxy s6 edge plus 上进行测试。

【问题讨论】:

    标签: android cordova ionic-framework build


    【解决方案1】:

    请使用我在安卓设备上测试过的这段代码。它可以根据您的需要工作。只需增加相机选项。以下是选项。

                quality: 75,
                destinationType: Camera.DestinationType.DATA_URL,
                sourceType: Camera.PictureSourceType.CAMERA,
                allowEdit: true,
                encodingType: Camera.EncodingType.JPEG,
                targetWidth: 300,
                targetHeight: 300,
                popoverOptions: CameraPopoverOptions,
                saveToPhotoAlbum: false
    

    如果您有任何疑问,请随时与我联系。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-27
      • 1970-01-01
      • 1970-01-01
      • 2018-09-18
      • 2021-11-13
      • 1970-01-01
      • 1970-01-01
      • 2015-04-02
      相关资源
      最近更新 更多