首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Phonegap getPicture函数长延迟,恢复回忆

Phonegap getPicture函数长延迟,恢复回忆
EN

Stack Overflow用户
提问于 2014-03-26 19:11:25
回答 1查看 1.7K关注 0票数 2

在Android设备上用Cordova /Phonegap3.2应用程序拍摄照片时,我遇到了问题。

当我运行navigator.camera.getPicture函数时,相机在大约30秒后返回成功,有时更长。但是,当我再次点击相机按钮(再次运行navigator.camera.getPicture函数,而不捕捉镜头)时,它立即将控件返回到应用程序,并恢复应用程序的进程。

看起来就像我拍完照片后它挂在应用程序上一样(虽然我在相机拍完照片后返回到应用程序),而导致相机继续运行并进入success function的唯一原因是再次运行getPicture函数。

这在iOS7上没有发生,我只在安卓上体验过(尝试了2.3.5,4.1.2)。

我在navigator.camera.getPicture调用之前设置了一个警报,它运行正常。我还在成功函数中设置了一个警报,但它没有运行。因此,我假设捕获插件中的其他东西会导致延迟。

我检查过CPU,它很低。我禁用了任何其他后台进程和webservice调用,以确保它不会导致这种行为。

我还使用了一个非常小的图像大小,以确保图像的大尺寸不会导致这个问题。所以我也消除了图像大小的因素。

getPicture函数:

代码语言:javascript
复制
 navigator.camera.getPicture(function () {   
        // On get photo success

        that._onPhotoURISuccess.apply(that, arguments);
         return false;
    }, function (err) {


    }, {
        quality: CAPTURED_PHOTO_IMAGE_QUALITY,
        destinationType: Camera.DestinationType.FILE_URI, 
        encodingType: Camera.EncodingType.JPEG,
        saveToPhotoAlbum: SETTINGS_SAVE_TO_PHOTO_ALBUM,
        allowEdit: false,
        sourceType: Camera.PictureSourceType.CAMERA, 
        targetWidth: maxSize, // <= 1024
        targetHeight: maxSize, 
        correctOrientation: true,  
    });

行为1的日志:

保存图像后:

代码语言:javascript
复制
03-27 21:11:10.812: V/webview(11988):  singleCursorHandlerTouchEvent -getEditableSupport  FASLE 
03-27 21:11:11.281: D/CordovaActivity(11988): Paused the application!
03-27 21:11:11.281: D/CordovaWebView(11988): Handle the pause
03-27 21:11:11.296: W/PluginManager(11988): THREAD WARNING: exec() call to Camera.takePicture blocked the main thread for 33ms. Plugin should use CordovaInterface.getThreadPool().
03-27 21:11:11.382: W/PluginManager(11988): THREAD WARNING: exec() call to WebSocket.send blocked the main thread for 18ms. Plugin should use CordovaInterface.getThreadPool().
03-27 21:11:12.117: W/IInputConnectionWrapper(11988): showStatusIcon on inactive InputConnection
03-27 21:11:17.070: D/CordovaActivity(11988): Incoming Result
03-27 21:11:17.070: D/CordovaActivity(11988): Request code = 34
03-27 21:11:17.070: D/CordovaActivity(11988): We have a callback to send this result to
03-27 21:11:17.585: D/dalvikvm(11988): GC_EXTERNAL_ALLOC freed 563K, 52% free 4167K/8519K, external 5208K/5208K, paused 85ms
03-27 21:11:18.734: D/dalvikvm(11988): GC_EXPLICIT freed 19K, 52% free 4161K/8519K, external 8280K/8422K, paused 64ms
03-27 21:11:18.750: D/Whitelist(11988): Unlimited access to network resources
03-27 21:11:18.757: I/CordovaLog(11988): Found start page location: index.html
03-27 21:11:18.757: D/Config(11988): The <log> tags is deprecated. Use <preference name="loglevel" value="DEBUG"/> instead.
03-27 21:11:18.757: I/CordovaLog(11988): Changing log level to DEBUG(3)
03-27 21:11:18.757: D/CordovaActivity(11988): Resuming the App
03-27 21:11:18.757: D/CordovaActivity(11988): CB-3064: The errorUrl is null
03-27 21:11:18.789: V/webview(11988): OnSizeChanged: Enter 
03-27 21:11:18.804: D/SoftKeyboardDetect(11988): Ignore this event
03-27 21:11:19.125: V/webview(11988): OnSizeChanged: Enter 

两分钟后,我决定再次点击相机按钮:

代码语言:javascript
复制
03-27 21:13:07.539: D/dalvikvm(11988): GC_CONCURRENT freed 2057K, 52% free 4189K/8647K, external 408K/5208K, paused 4ms+5ms
03-27 21:13:37.539: D/dalvikvm(11988): GC_CONCURRENT freed 574K, 52% free 4177K/8647K, external 408K/5208K, paused 4ms+4ms
03-27 21:13:57.515: V/webview(11988):  singleCursorHandlerTouchEvent -getEditableSupport  FASLE 
03-27 21:13:57.984: D/CordovaActivity(11988): Paused the application!
03-27 21:13:57.984: D/CordovaWebView(11988): Handle the pause
03-27 21:13:58.000: W/PluginManager(11988): THREAD WARNING: exec() call to Camera.takePicture blocked the main thread for 33ms. Plugin should use CordovaInterface.getThreadPool().
03-27 21:13:58.351: D/FileTransfer(11988): upload file:///mnt/sdcard/Android/data/com.test.test/cache/1395947477121.jpg to http://test.test.com/service.asmx/SaveImage
03-27 21:13:58.351: D/FileTransfer(11988): fileKey: file
03-27 21:13:58.351: D/FileTransfer(11988): fileName: 26346703-41cc-452c-8e86-aac088c99781.jpg
03-27 21:13:58.351: D/FileTransfer(11988): mimeType: image/jpeg
03-27 21:13:58.359: D/FileTransfer(11988): params: {}
03-27 21:13:58.359: D/FileTransfer(11988): trustEveryone: false
03-27 21:13:58.367: D/FileTransfer(11988): chunkedMode: false
03-27 21:13:58.367: D/FileTransfer(11988): headers: {"Connection":"close"}
03-27 21:13:58.367: D/FileTransfer(11988): objectId: 4
03-27 21:13:58.398: D/FileTransfer(11988): httpMethod: POST
03-27 21:13:58.398: W/PluginManager(11988): THREAD WARNING: exec() call to FileTransfer.upload blocked the main thread for 96ms. Plugin should use CordovaInterface.getThreadPool().
03-27 21:13:58.398: D/FileTransfer(11988): Content Length: 28412
03-27 21:13:58.625: D/dalvikvm(11988): GC_CONCURRENT freed 453K, 51% free 4312K/8647K, external 408K/5208K, paused 4ms+5ms
03-27 21:13:58.914: D/FileTransfer(11988): Sent 28412 of 28412
03-27 21:13:59.156: W/IInputConnectionWrapper(11988): showStatusIcon on inactive InputConnection
03-27 21:13:59.257: D/FileTransfer(11988): response code: 200
03-27 21:13:59.281: D/FileTransfer(11988): response headers: {null=[HTTP/1.1 200 OK], Access-Control-Allow-Headers=[Content-Type], Access-Control-Allow-Origin=[*], Cache-Control=[private, max-age=0], Connection=[Close], Content-Length=[0], Date=[Thu, 27 Mar 2014 19:14:50 GMT], Server=[Microsoft-IIS/8.0], X-Android-Received-Millis=[1395947639258], X-Android-Response-Source=[NETWORK 200], X-Android-Sent-Millis=[1395947638596], X-AspNet-Version=[4.0.30319], X-Powered-By=[ASP.NET]}
03-27 21:13:59.281: D/FileTransfer(11988): got response from server
03-27 21:14:00.796: D/CordovaActivity(11988): Incoming Result
03-27 21:14:00.796: D/CordovaActivity(11988): Request code = 34
03-27 21:14:00.796: D/CordovaActivity(11988): We have a callback to send this result to
03-27 21:14:00.835: D/Whitelist(11988): Unlimited access to network resources
03-27 21:14:00.843: I/CordovaLog(11988): Found start page location: index.html
03-27 21:14:00.843: D/Config(11988): The <log> tags is deprecated. Use <preference name="loglevel" value="DEBUG"/> instead.
03-27 21:14:00.976: I/CordovaLog(11988): Changing log level to DEBUG(3)
03-27 21:14:00.976: D/CordovaActivity(11988): Resuming the App
03-27 21:14:00.976: D/CordovaActivity(11988): CB-3064: The errorUrl is null
03-27 21:14:01.070: V/webview(11988): OnSizeChanged: Enter 
03-27 21:14:01.078: D/SoftKeyboardDetect(11988): Ignore this event
03-27 21:14:01.289: V/webview(11988): OnSizeChanged: Enter 
03-27 21:14:01.609: D/skia(11988): purging 197K from font cache [29 entries]

更新2:我注意到了另一件事。当我在getPicture函数的错误回调中设置一个警告时,我会得到“”错误。虽然当我再次启动相机,成功的回调被调用。

更新3:另一个经历了同样的问题的人

我在更多细节中遇到的三种行为:

行为1:

  1. 我点击相机捕捉按钮
  2. 单击以将照片保存在照相机预览窗口中。
  3. 什么都不会发生,成功或失败的回调都会被调用(等待2分钟)。
  4. 我再次单击相机按钮,调用成功的回调,然后单击相机预览窗口的后退按钮。
  5. 我能在视图中看到图像
  6. 从我第二次按下相机按钮(我假设是从第二个按钮)得到失败回调。

行为2:

  1. 我点击相机捕捉按钮
  2. 5-30秒后,调用成功的回调。
  3. CPU为100% (上传图像)
  4. 上传成功函数

行为3:

  1. 我点击相机捕捉按钮
  2. 我取消了捕获,然后返回到应用程序
  3. 在大约结束后调用失败回调。15秒
  4. 如果在第2步之后单击相机按钮,我将立即得到失败回调。

这些是主要问题。这三种方法的共同之处在于,当我用第二个摄像机getPicture调用(按下相机按钮)中断延迟时,回调函数的长时间延迟和立即继续。

这些问题并不一致。在罕见的情况下,它确实按预期工作,没有延误,但大多数时候我会遇到这些问题。问题可能发生在我启动应用程序之后或一段时间之后,并且没有办法调试它们,因为延迟发生在相机插件本身,而不是在我的代码中。

EN

回答 1

Stack Overflow用户

发布于 2014-08-17 11:18:56

我在phonegap 2.9.0上也遇到了同样的问题,在做了多次失败的试验来解决这个问题后,我做了以下工作

  • 我创建了一个新的phonegap 3.5.0项目
  • 我从CLI构建了android平台。
  • 我将www文件夹复制到新的项目根文件夹中。
  • 我使用CLI添加了所有需要的插件。
  • 我在顶级config.xml文件中为图标和启动屏幕做了必要的更改,因为文件结构不同。
  • 我负责这个项目,现在没事了。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22670896

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档