【发布时间】:2014-03-26 19:11:25
【问题描述】:
我在 Android 设备上的 Cordova / Phonegap 3.2 应用程序中拍摄照片时遇到问题。
当我运行navigator.camera.getPicture 函数时,相机会在大约 30 秒后返回成功,有时会更长。但是,当我再次点击相机按钮时(再次运行 navigator.camera.getPicture 函数,没有捕捉镜头),它会立即将控制权返回给应用程序并恢复应用程序的进程。
它看起来就像我拍摄图像后卡住的应用程序(尽管我确实在相机完成拍摄照片后返回应用程序),以及唯一导致相机继续操作并进入 @ 987654324@ 是通过再次运行getPicture 函数。
这在 iOS7 上不会发生,我只在 Android 上体验过(在 Android 版本 2.3.5、4.1.2 上尝试过)。
我在navigator.camera.getPicture 调用之前发出了警报,它运行正常。我还在成功功能中发出了警报,但它没有运行。所以我假设捕获插件中的其他东西会导致延迟。
我检查了 CPU,它是低的。我禁用了任何其他后台进程和 Web 服务调用,以确保它不会导致此行为。
我还使用了非常小的图像尺寸以确保图像的大尺寸不会导致此问题。所以我也消除了图像尺寸因素。
getPicture 函数:
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:
图片保存后:
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
两分钟后,我决定再次点击相机按钮:
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 函数的错误回调发出警报时,我收到“Cameera cancelled”错误。虽然当我再次启动相机时,会调用成功回调。
更新3:另一个experienced the same issue
我更详细地遇到的三种行为:
行为 1:
- 我点击相机拍摄按钮
- 单击以将照片保存在相机预览窗口中
- 什么都没有发生,调用成功或失败回调(等待 2 分钟)
- 我再次点击相机按钮,调用成功回调,我点击后退按钮相机预览窗口
- 我可以在视图中看到图像
- 从我第二次按下相机按钮时获取失败回调(我假设它来自第二次)
行为 2:
- 我点击相机拍摄按钮
- 5-30 秒后调用成功回调
- CPU 为 100%(正在上传图片)
- 上传成功函数调用
行为 3:
- 我点击相机拍摄按钮
- 我取消捕获并返回应用程序
- 在大约 10 分钟后调用失败回调。 15 秒
- 如果我在第 2 步之后立即单击相机按钮,我会立即收到失败回调
这些是主要问题。这三个的共同点是长时间延迟和回调函数的立即延续,当我用第二个相机 getPicture 调用(按下相机按钮)中断延迟时。
问题不一致。在极少数情况下,它确实按预期工作,没有延迟,但大多数时候我都会遇到这些问题。这些问题可能在我启动应用程序后或一段时间后立即发生,并且无法调试它们,因为延迟发生在相机插件本身,而不是我的代码中。
【问题讨论】:
-
能否请您提供用于调用 getPicture 的代码?而且,您是否尝试过使用cordova 3.3 / 3.4?
-
嗨,已更新代码。由于 ApplicationBuilder 环境的限制,我不能使用除 3.2 之外的 Cordova。我正在使用最新版本的文件、文件传输、媒体捕捉和相机插件。
-
您已经使用
targetsize进行了测试,您是否也尝试过不同的(小)quality值?我在我们的应用程序中使用它,在 android 上第一次启动很慢,但在普通手机上大约 2-3 秒.. :/ -
我尝试了 10px 大小的图像和 10 质量,同样的问题。这家伙也有同样的问题:groups.google.com/forum/#!topic/phonegap/7nmRrQoO8zU
-
@PaoloCasciello 我已经用相关的调试跟踪和更详细的信息更新了这个问题。
标签: javascript android cordova cordova-3