【问题标题】:App closing after choosing image or taking picture选择图像或拍照后关闭应用程序
【发布时间】:2012-07-11 19:11:08
【问题描述】:

我在 Dreameweaver CS6 中使用最新版本的 phonegap 软件。我从 github 网站上获取了起始示例 HTML 文件并将其导入 DW。然后,我测试了该应用程序,并使用了我的位置、地图等。

但是,我现在更改了代码,以便能够在我的 Android 手机上拍照或选择图片,并且每次我这样做/或关闭应用程序时。

HTML代码是:

<!DOCTYPE html>
<html>
  <head>
    <title>Capture Photo</title>
    <script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
    <script type="text/javascript" charset="utf-8">
    var pictureSource;   // picture source
    var destinationType; // sets the format of returned value 

    document.addEventListener("deviceready",onDeviceReady,false);

    function onDeviceReady() {
        pictureSource=navigator.camera.PictureSourceType;
        destinationType=navigator.camera.DestinationType;
    }

    function onPhotoDataSuccess(imageData) {
      var smallImage = document.getElementById('smallImage');
      smallImage.style.display = 'block';
      smallImage.src = imageData;
    }

    function onPhotoURISuccess(imageURI) {
      var largeImage = document.getElementById('largeImage');

      largeImage.style.display = 'block';
      largeImage.src = imageURI;
    }

    function capturePhoto() {
      navigator.camera.getPicture(getPhoto, onFail, { quality: 50, destinationType: destinationType.FILE_URI });
    }

    function capturePhotoEdit() {
      // Take picture using device camera, allow edit, and retrieve image as base64-encoded string  
      navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 100, allowEdit: false }); 
    }

    function getPhoto(source) {
      // Retrieve image file location from specified source
      navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 100, 
        destinationType: destinationType.FILE_URI,
        sourceType: source });
    }

    function onFail(message) {
      alert('Failed because: ' + message);
    }

    </script>
  </head>
  <body>
    <button onclick="capturePhoto();">Capture Photo</button> <br>
    <button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
    <img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
    <img style="display:none;" id="largeImage" src="" />
  </body>
</html>

而 config.xml 是:

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns       = "http://www.w3.org/ns/widgets"
    xmlns:gap       = "http://phonegap.com/ns/1.0"
    id              = "com.xxxxxxxx.DKGApp"
    version         = "1.0.0">

    <name>DKG App</name>

    <description>
        An app that allows uploading their random images they take to our facebook website!
    </description>

    <author href    ="http://www.xxxxxxxx.com"  email       ="mail@xxxxxxxx.com">
        David
    </author>

    <gap:splash src="splash.png" />

    <icon src="icon.png" gap:role="default" />

    <feature name="http://api.phonegap.com/1.0/network" />
    <feature name="http://api.phonegap.com/1.0/camera"/>
    <feature name="http://api.phonegap.com/1.0/file"/>
    <feature name="http://api.phonegap.com/1.0/media"/>

    <preference name="android-minSdkVersion" value="7" />
    <preference name="orientation" value="portrait" />
    <preference name="target-device" value="universal" />
</widget>

我是否遗漏了一些必要的东西才能让它工作而不是每次都崩溃?

谢谢!

【问题讨论】:

  • 您是否在日志中看到任何错误 (adb logcat)??
  • @dhaval: 我不知道如何使用 adb logcat...?
  • 如果您使用 Eclipse,只需打开 DDMS 透视图,您应该会看到所有消息。如果是内存问题,请按照西蒙下面提到的内容进行操作。
  • 好的,这是日志文件...希望对您有所帮助! pastebin.com/fDxRMpYe
  • 你能把你更新的源代码放到 pastebin 里吗?还有你用的是哪个安卓版本??

标签: javascript android html cordova phonegap-plugins


【解决方案1】:

您遇到内存不足错误。请不要使用 DATA_URL。返回一个 3000x2000 像素的 base64 编码图像会占用应用程序中的所有可用内存。请改用 FILE_URI。

【讨论】:

  • 您能举个例子,说明在我上面的代码中放置 FILE_URI 的位置吗?
  • 我已经更改了 OP 中 capturePhoto()onPhotoDataSuccess(imageData) 的代码,但在单击选中标记以接受捕获的图像。
  • 当我使用 Dreamweaver 作为我的 DEV 环境时,我该怎么做?
  • 抱歉,不知道。我不使用 DW。
  • 我有同样的问题,唯一解决的方法是将图像文件缩小到 1000 像素以下,但这不是解决方案,我仍然找不到正确解决的方法使用更大的图像。
【解决方案2】:

我也遇到了同样的问题。我使用foreground-camera-plugin解决了这个问题。

只需转到此链接并按照步骤操作即可。

https://code.google.com/p/foreground-camera-plugin/

【讨论】:

    猜你喜欢
    • 2013-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-11
    • 2014-09-26
    • 2017-02-24
    • 1970-01-01
    相关资源
    最近更新 更多