【问题标题】:Phonegap : Camera not working in android kitkatPhonegap:相机在android kitkat中不起作用
【发布时间】:2015-10-02 15:14:39
【问题描述】:

我正在为相机应用程序在 Android 中开发应用程序。我使用cordova插件添加相机

config.xml

 <feature name="Camera">
    <param name="android-package" value="org.apache.cordova.camera.CameraLauncher" />
</feature>

拍照代码

 function snapPicture () {
    navigator.camera.getPicture (onSuccess, onFail, 
        { quality: 100,  
          sourceType: navigator.camera.PictureSourceType.CAMERA,
          mediaType: navigator.camera.MediaType.PICTURE,
          destinationType: destinationType.FILE_URI,
          encodingType: navigator.camera.EncodingType.JPEG,
          correctOrientation: false,
          saveToPhotoAlbum: true
         });


    //A callback function when snapping picture is success.
    function onSuccess (imageData) {
        var image = document.getElementById ('picture');
        alert("path : "+imageData);
        image.src =  imageData;
    }

    //A callback function when snapping picture is fail.
    function onFail (message) {
        alert ('Error occured: ' + message);
    }
}

该代码在除 Android Kitkat 之外的所有 Android 版本中都能正常工作。在 Kitkat 中,我得到的响应是“Error capture image

谁能告诉我 Kitkat 的问题是什么 提前谢谢...!

【问题讨论】:

  • 您使用哪个科尔多瓦版本?通过键入cordova -v 在终端中检查它,同时请在您的项目中查看cordova android 的版本。检查在你的项目目录中运行cordova platform version
  • @Sithys 正在使用 cordova 4.2.0。并尝试在 kitkat 4.4.4 中运行
  • 我需要cordova android的平台版本。由于新实施的 webview,kitkat 存在许多问题。所以...我认为,您正在发现一个已经解决的问题。在 windows 上以管理员身份运行 cmd,或在 mac 上以 sudo 开头。 npm update -g cordova
  • @Sithys 所以你说更新科尔多瓦来解决这个问题..
  • 这就是我所说的。如果您没有比以前评论更多的详细信息,则无需为此类事情写评论。

标签: android cordova phonegap-plugins phonegap-build


【解决方案1】:

您在代码中犯了一个错误。 destinationType: destinationType.FILE_URI, 不起作用。将该行改为destinationType: Camera.DestinationType.FILE_URI,,它就会运行。这是您的完整工作代码:

function snapPicture() {
        navigator.camera.getPicture(onSuccess, onFail, { quality: 100,
             sourceType: navigator.camera.PictureSourceType.CAMERA,
             mediaType: navigator.camera.MediaType.PICTURE,
             destinationType: Camera.DestinationType.FILE_URI,
             encodingType: navigator.camera.EncodingType.JPEG,
             correctOrientation: false,
             saveToPhotoAlbum: true
             })


             //A callback function when snapping picture is success.
             function onSuccess (imageData) {
                 var image = document.getElementById ('picture');
                 alert("path : "+imageData);
                 image.src =  imageData;
             }

             //A callback function when snapping picture is fail.
             function onFail (message) {
                 alert ('Error occured: ' + message);
             }
    }

我建议您使用GapDebug 来调试您的应用程序。

【讨论】:

  • 我尝试了代码,但我仍然收到错误为“错误捕获图像”。仅在 Android Kitkat 中出现此错误
  • 你尝试过像我提到的那样使用 GapDebug 吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-06
  • 2014-08-27
相关资源
最近更新 更多