我在Android設備上的Cordova/Phonegap 3.2應用程序中捕獲照片時遇到問題。Phonegap getPicture函數長延遲,恢復召回
當我運行navigator.camera.getPicture
功能時,相機在約30秒後返回成功,有時會更長。但是,當我再次點擊相機按鈕(再次運行navigator.camera.getPicture函數,而不捕獲鏡頭)時,它將immedietyl控制權返回給應用程序並恢復應用程序的進程。
它看起來像捕捉圖像後卡住的應用程序(雖然在相機完成拍攝照片後我會返回到應用程序),並且導致相機繼續操作並進入success function
是通過再次運行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取消」錯誤。雖然當我再次啓動相機時,成功回調被調用。
更新3:另一個人誰experienced the same issue
,我在更多的細節會遇到三種行爲:
行爲1:
- 我點擊相機拍攝按鈕
- 點擊將照片保存在相機預覽窗口中
- 沒有任何反應,成功還是失敗的回調被稱爲(等待2分鐘)
- 我再次點擊拍照鍵,成功回調被調用時,我點擊後退按鈕時,相機預覽窗口
- 我可以看到在觀看圖片
- 獲取從我第二次按下相機按鈕故障回調(我認爲它與第二個是)
行爲2:
- 我點擊相機拍攝按鈕
- 後5-30秒內成功回調被稱爲
- CPU爲100%(上傳圖片)叫
行爲
- 我點擊相機拍攝按鈕
- 我取消捕獲並返回到應用程序
- 在約1秒鐘後調用失敗回調。 15秒
- 如果我點擊第2步之後的拍照鍵,我得到的失敗回調立即
這些是主要問題。這三種情況的共同之處在於,當我用第二臺相機getPicture調用(按下相機按鈕)中斷延遲時,延遲時間很長,並立即延續了回調功能。
問題不一致。在極少數情況下,它確實按預期工作,沒有延遲,但大多數時候我遇到這些問題。這些問題可能在我啓動應用程序後或一段時間後發生,並且無法調試它們,因爲延遲發生在相機插件本身中,而不是在我的代碼中。
請問您可以包含您用於調用getPicture的代碼嗎?而且,你是否嘗試過使用cordova 3.3/3.4? –
嗨,更新了代碼。由於ApplicationBuilder環境的限制,我無法使用Cordova 3.2以上的版本。儘管我正在使用最新版本的File,FileTransfer,Media Capture和Camera插件。 –
你已經用'targetsize'進行了測試,你是否還嘗試過不同(小)'質量'值?我在我們的應用程序中使用它,並在Android上第一次啓動緩慢,但在平均手機上大約2-3秒..:/ –