cordova 2.9相机插件:回调在android中不起作用

时间:2014-06-26 10:52:27

标签: javascript android ios cordova camera

我正在使用cordova 2.9相机插件,代码如下:

function browseFiles() {
                    alert("browsing files... ");
                    var options = {
                        sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
                        quality: 45, // previously 50.  Stay below 50 per Phonegap doc about IOS memory issues
                        destinationType: Camera.DestinationType.DATA_URL,
                        //encodingType: Camera.EncodingType.JPEG,
                        //saveToPhotoAlbum: true,
                        correctOrientation: true,
                        // I get OutOfMemoryError on Samsung Galaxy S3 (and other Android) if I don't specify size.
                        // see thread:  https://groups.google.com/forum/?fromgroups=#!topic/phonegap/YWZlnFUfRjE
                        targetWidth: 400,
                        targetHeight: 400
                    };
                    NativeBridge.captureImage(function (_data) {
                        //alert("data: " + _data);
                        $("#MyImage").attr('src', "data:image/jpeg;base64," + _data);
                        $("#MyImage").attr('data-base64', _data);
                    }, undefined, options);
                };

captureImage: function (cameraSuccess, cameraError,customOptions) {




            if (!cameraError) {
                cameraError = function (message) {
                    NativeBridge.alert('Failed because: ' + message);
                }
            }
            if (JSContext.getIsWebApp() == true) {
                WebApp.captureImage(cameraSuccess, cameraError, customOptions);
            }
            else {
                if (navigator.camera && navigator.camera.getPicture) {
                    try {
                        var options = {};

                        if (customOptions) {
                            options = customOptions;
                        } else {
                            options = {
                                sourceType: Camera.PictureSourceType.CAMERA,
                                quality: 45, // previously 50.  Stay below 50 per Phonegap doc about IOS memory issues
                                destinationType: Camera.DestinationType.DATA_URL,
                                //encodingType: Camera.EncodingType.JPEG,
                                //saveToPhotoAlbum: true,
                                correctOrientation: true,
                                // I get OutOfMemoryError on Samsung Galaxy S3 (and other Android) if I don't specify size.
                                // see thread:  https://groups.google.com/forum/?fromgroups=#!topic/phonegap/YWZlnFUfRjE
                                targetWidth: 400,
                                targetHeight: 400
                            };
                        }
                        // Old Options {quality: 50,destinationType: Camera.DestinationType.DATA_URL }
                        navigator.camera.getPicture(cameraSuccess, cameraError, options);
                    }
                    catch (err) {
                        cameraError(err);
                    }
                }
                else {
                    NativeBridge.alert("Camera is not supported");
                }

            }
        }

    }

但是在任何Android设备上都不会调用回调。 在iPhone上它正常工作,我调试了应用程序,这就是logcat中的内容:

06-26 16:34:47.417: W/IInputConnectionWrapper(27159): showStatusIcon on inactive InputConnection
    1:35 PM
    06-26 16:35:07.792: I/Info(27159): width : 1280
    1:35 PM
    06-26 16:35:07.792: I/Info(27159): height : 720
    1:35 PM
    06-26 16:35:07.822: D/WebView(27159): loadUrlImpl: called
    1:35 PM
    06-26 16:35:07.822: D/webcore(27159): CORE loadUrl: called
    1:36 PM
    06-26 16:35:07.872: V/CustomViewBehind(27159): behind INVISIBLE
    1:36 PM
    06-26 16:35:08.227: I/Info(27159): width : 720
    1:36 PM
    06-26 16:35:08.227: I/Info(27159): height : 1280
    1:36 PM
    06-26 16:35:08.337: I/System.out(27159): Not a DRM File, opening notmally
    1:36 PM
    06-26 16:35:08.337: I/System.out(27159): buffer returned 
    1:36 PM
    06-26 16:35:08.342: V/CustomViewBehind(27159): behind INVISIBLE
    1:36 PM

非常感谢任何帮助

0 个答案:

没有答案